13

wsl -h shows the following:

    --exec, -e <CommandLine>   Execute the specified command without using the default Linux shell.
    --   Pass the remaining command line as is.

What does "without using the default Linux shell" mean (i.e. what else is it going to use, if not the default shell!?)?.

Additionally, by way of an example, I now have three possible ways to run Linux ls from my PowerShell prompt (i.e. this will not be Get-ChildItem aliased to ls, but instead a Linux command via WSL):

PS C:\> wsl -e ls   # Alternatively,  wsl --exec ls
PS C:\> wsl -- ls
PS C:\> wsl ls

But all outputs appear to be the same. How would you explain the differences between these three ways of running a WSL Linux command from a PowerShell prompt?

1
  • 3
    with wsl ... /bin/bash is used. With wsl -e .... The shell is env. This has more relevance when you are running shell scripts on wsl. Commented Feb 11, 2021 at 9:12

2 Answers 2

10

I think it means wsl runs the command directly, instead of spawning a shell process to run the command.

For example, if I run :

wsl -e sleep 10

From another terminal, I have :

root      1482     1  0 11:32 tty3     00:00:00 /init
ubuntu    1483  1482  0 11:32 tty3     00:00:00 sleep 10

We can see /init is the parent of sleep 10, without a shell in between.

Sign up to request clarification or add additional context in comments.

Comments

-1

A cool trick is using this to set the X11 $DISPLAY variable, letting you use windows terminal to get remote shells using WSLG.

# in microsoft terminal or powershell use this command line
wsl.exe -- ssh -a -X -Y $hostname

then on the remote system

# DISPLAY will show something like localhost:10.0 on the remote system
echo $DISPLAY
# use a program like xeyes to test
xeyes

3 Comments

This sounds good, but I tried it and can't get it to work. Where you say $hostname I assumed you meant replacing that by the IP or hostname of the remote Linux system, I've tried both ways, and all that happens is that I ssh onto the remote system. Then, echo $DISPLAY shows nothing ... Typing xeyes results in Error: Can't open display:. Are you running on Windows 11? I'm using Windows 10, but I have setup my WSL to support GUI apps, so I thought this should work.
@YorSubs yes, you need to have Win11, or at least a recently patched windows 10. WSLG is in windows 11. You need to have WSL2 + WSLG specifically. github.com/microsoft/wslg/issues/730

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.