13

I'm on a Windows 10 machine with Windows Subsystem for Linux enabled/configured (Ubuntu). To explain my problem let me present you with two scenarios:

Scenario 1:

  1. I start a cmd.exe prompt
  2. I run bash in the cmd.exe prompt
  3. (inside bash) I run a given command, called dwiextract in my case (from a neuroimaging analysis software package)

Works fine suggesting a successful installation of the software package.

Scenario 2:

  1. I start a cmd.exe prompt
  2. I attempt to pass the exact same command directly to bash from cmd.exe by using the following syntax: bash -c dwiextract

I get command not found.

(Note I learned about bash -c here and have used it successfully in other occasions.)

The following image shows exactly what I've done:

example_diagram

My question: Shouldn't these two scenarios be equivalent. Why does Scenario 1 work and Scenario 2 does not work?

Many thanks.

2
  • 2
    Likely related: bash -c and noninteractive shell Commented Apr 21, 2018 at 16:51
  • 1
    Running bash as an interactive shell (using -i option) solved my problem. Thanks steeldriver.
    – fnery
    Commented Apr 21, 2018 at 17:24

2 Answers 2

12

Running bash as an interactive shell (using -i option) solved my problem.

That is: bash -c -i <command>.

3
  • 3
    ... because the $PATH was not the same in the two shells, and starting an interactive shell forces bash to read the bashrc file, where the PATH is set.
    – Kusalananda
    Commented Apr 21, 2018 at 18:36
  • I had to use exactly this: wsl -d Ubuntu-20.04 -u robert bash -c -i "cd /mnt/c/fastai2 && conda activate fastai2 && jupyter lab"
    – BSalita
    Commented Jun 26, 2020 at 16:06
  • I had tried all options from this thread and nothing works still it says: /bin/bash Command not found Commented Feb 27, 2021 at 12:35
0

In addition to ... bash -c -i "..." this worked well for me

wsl -d Debian -u myname -e dwiextract

also with parameters

wsl -d Debian -u myname -e uname -a

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .