I am facing the same issue here: Passing command to bash from cmd.exe (WSL) not working

Except that for me the solutions there do not work either.

I have WSL installed, and I am trying to run a command called "bet" from cmd.exe by

  1. opening cmd.exe
  2. typing bash -c -i "bet"

which throws an error:

Command 'bet' not found, did you mean:

  command 'bget' from deb ax25-tools (0.0.10-rc4-3build1)
  command 'bst' from deb buildstream (1.4.1-1)
  command 'beet' from deb beets (1.4.9-4)
  command 'btt' from deb blktrace (1.2.0-5)
  command 'bat' from deb bacula-console-qt (9.4.2-2ubuntu5)
  command 'ben' from deb ben (0.9.0ubuntu2)
  command 'fet' from deb fet (5.42.2-2build1)
  command 'eet' from deb libeet-bin (1.23.3-8)
  command 'net' from deb samba-common-bin (2:4.13.17~dfsg-0ubuntu1.20.04.1)

Try: sudo apt install <deb name>

When I try doing this by opening cmd.exe and typing bash, and then typing "bet" to the linux command line, it works fine.

I have also tried doing this with wsl -e "bet" however that also does not achieve what I'm trying to do. (The bet command receives additional parameters which I add to the end, but the command does not go through. The command does go through if I run bet from linux shell directly).

FYI: Bet is a brain extraction tool which comes with FSL (https://fsl.fmrib.ox.ac.uk/fsl/fslwiki)

  • 2
    Running a normal interactive bash shell in WSL, what does type bet return? Oct 26, 2022 at 10:30
  • "When I try doing this by opening cmd.exe and typing bash, and then typing "bet" to the linux command line, it works fine." When it works, then also note what type bet outputs, then use that in your bash -c command.
    – Kusalananda
    Oct 26, 2022 at 12:45
  • type bet returns bet is /usr/local/fsl/bin/bet @roaima @Kusalananda the issue is I really need to call this command directly using "bet" because these commands are called from a seperate program/script. I am not the one writing these commands. It is a script. How can I make it so that bash -c -i "bet" works?
    – Tamer
    Oct 26, 2022 at 17:52

1 Answer 1


As I know nothing about Windows and its cmd.exe, this answer assumes a Unix environment. WSL is, in most user-visible ways, a Unix environment.

If this is a question regarding the use of cmd.exe, then the question may find a more appropriate audience on the SuperUser site.

The issue seems to be that the path to the bet executable is not in the search path for the non-interactive shell you are starting.

There are a few different solutions:

  1. Use the exact pathname of the executable:

    bash -c '/usr/local/fsl/bin/bet'
  2. Change the PATH variable's value inside the bash -c script, before calling bet:

    bash -c 'PATH=$PATH:/usr/local/fsl/bin; bet'
  3. Append the appropriate directory path to the PATH environment variable when you start the bash -c command. This could be done in either of these ways:

    PATH=$PATH:/usr/local/fsl/bin bash -c bet
    env PATH="$PATH:/usr/local/fsl/bin" bash -c bet
  4. Append the appropriate directory path to the PATH environment variable by modifying the current shell's environment. This would be done by adding the following to one's shell's startup files (typically ~/.bash_profile for the bash shell):


    This would take effect with the next login shell session. Then use

    bash -c bet
  5. In the question, you also include the -i option when you start the bash -c command. This would make the shell an interactive shell, and it would parse the ~/.bashrc file. Another option would therefore be to add


    to the ~/.bashrc file, but be aware that the purpose of this file is to set up the shell for interactive work, which may include running commands you don't want to run every time you start bet. As an alternative, you can therefore add the above variable assignment to a brand new file and then start bash with

    bash -i --rcfile envfile -c bet

    ... where envfile is the new file.

  6. If you have a file with the assignment mentioned in the previous point, you may start bash in one of the following ways

    BASH_ENV=envfile bash -c bet
    env BASH_ENV="envfile" bash -c bet

    Doing so would avoid having to run bash as an interactive shell (apart from parsing ~/.bashrc by default, running the shell in interactive mode has other implications for the shell, like enabling job control).

  • 1
    Thanks a lot! Solution 5. worked best for me! Additionally, I needed to also add these inside ~/.bashrc Such as: # FSL Setup FSLDIR=/usr/local/fsl PATH=${FSLDIR}/bin:${PATH} export FSLDIR PATH . ${FSLDIR}/etc/fslconf/fsl.sh
    – Tamer
    Oct 27, 2022 at 8:53

You must log in to answer this question.

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