1
0 Comments

With WSL 1, the output of wsl.exe --help includes the following usage information:

Usage: wsl.exe [Argument] [Options...] [CommandLine]

Arguments to run Linux binaries:

If no command line is provided, wsl.exe launches the default shell.

--exec, -e <CommandLine>
    Execute the specified command without using the default Linux shell.

Therefore, the difference between wsl.exe foo and wsl.exe --exec foo is as follows:

  • wsl.exe foo launches the default shell configured for your WSL distribution and passes the command foo to it to be executed.
  • wsl.exe --exec foo executes the command foo directly, without involving the default shell.

For example, if the default shell for your WSL distribution is bash, you can use wsl.exe --exec fish to run the fish shell directly, without involving bash.

Both wsl.exe foo and wsl.exe --exec foo can be used to run the foo command in your WSL distribution. However, wsl.exe --exec foo allows you to bypass the default shell and execute the command directly.

To further illustrate the difference between wsl.exe foo and wsl.exe --exec foo, consider the following example:

wsl.exe -d Ubuntu fish
wsl.exe -d Ubuntu --exec fish

Both of these commands will start the fish shell in the Ubuntu WSL distribution. However, the first command will start the bash shell (which is the default shell for Ubuntu) and then run the fish command within it, while the second command will start the fish shell directly, without involving the default shell.

You can use the ps command to see the processes that are running in your WSL distribution. If you run ps after starting the fish shell using either of the above commands, you should see fish and ps as the only processes listed. This is because fish is the only process that was started, regardless of whether it was started directly or through the default shell.

So, what is the purpose of the --exec option?

Askify Moderator Edited question May 4, 2023