First up, I'm going to recommend that you use the newer (Microsoft recommended)
wsl.exe command, rather than
bash.exe is still available, but Microsoft calls it a "historical command" that has been "replaced by"
wsl command also provides far more options than the older
The first problem you have is that there's a syntax/quoting error in your command line, so yes, the Windows Terminal tab is closing before you can read it. Best to run this from a PowerShell or CMD profile/tab first to be able to see the output:
PS> bash.exe -c -i -s ssh ip
usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface]
[-b bind_address] [-c cipher_spec] [-D [bind_address:]port]
[-E log_file] [-e escape_char] [-F configfile] [-I pkcs11]
[-i identity_file] [-J [user@]host[:port]] [-L address]
[-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
[-Q query_option] [-R address] [-S ctl_path] [-W host:port]
[-w local_tun[:remote_tun]] destination [command]
PS> bash.exe -c "ssh ip"
PS> wsl ssh ip
PS> wsl -e bash -c ssh ip
<displays usage information as above>
PS> wsl -e bash -c "ssh ip"
As you can see, if you are passing a command string to
bash -c, it needs to be quoted. Otherwise, bash is just seeing the
ssh without the
wsl command, on the other hand, does allow invocation directly without the quotes. It's basically smart enough to pass the remainder of the command-line (after all arguments/flags have been processed) into the default shell, quoted to the
-c argument. You can see an example of this above with the
wsl ssh ip.
Next you want to know how to keep the tab/shell open after running a command. This can be done several ways, but the easiest is to:
- Start a shell
- Run the first command
exec a replacement shell that will keep running
As you have experienced, just doing the first two of those will cause the shell to close when the command exits.
This will look something like:
wsl -e bash -c "ls; exec bash"