Passing command to bash from cmd.exe (WSL) not working
8,208
Running bash as an interactive shell (using -i
option) solved my problem.
That is: bash -c -i <command>
.
Author by
fnery
Updated on September 18, 2022Comments
-
fnery over 1 year
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:
- I start a
cmd.exe
prompt - I run
bash
in thecmd.exe
prompt - (inside
bash
) I run a given command, calleddwiextract
in my case (from a neuroimaging analysis software package)
Works fine suggesting a successful installation of the software package.
Scenario 2:
- I start a
cmd.exe
prompt - I attempt to pass the exact same command directly to
bash
fromcmd.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:
My question: Shouldn't these two scenarios be equivalent. Why does Scenario 1 work and Scenario 2 does not work?
Many thanks.
-
smw about 6 yearsLikely related: bash -c and noninteractive shell
-
fnery about 6 yearsRunning bash as an interactive shell (using -i option) solved my problem. Thanks steeldriver.
- I start a
-
Kusalananda about 6 years... because the
$PATH
was not the same in the two shells, and starting an interactive shell forcesbash
to read thebashrc
file, where thePATH
is set. -
BSalita almost 4 yearsI had to use exactly this:
wsl -d Ubuntu-20.04 -u robert bash -c -i "cd /mnt/c/fastai2 && conda activate fastai2 && jupyter lab"
-
Jiri Otoupal イり オトウパー about 3 yearsI had tried all options from this thread and nothing works still it says: /bin/bash Command not found