In Windows Terminal, you can create a profile and add some start-up command (through commandline option in settings.json file. So when you start your profile, WT is executing the command, but then it's exiting (we can see for a second the new tab).
When starting a wsl profile in Windows Terminal, how can I execute linux commands AND keeping the current shell open? (so I can see the result, and keep on typing commands).
NB: I want to keep the current shell. This workaround start another shell, so that does not work here:
"commandline": "wsl -e bash -c \"foobar=`ls -a`; echo $foobar; exec bash\"",
. .. .bash_aliases .bash_history .bash_logout .bashrc .lesshsQ .lesshst .profile .ssh .viminfo .vimrc
test@xxx:~$ echo $foobar
test@xxx:~$
If the profile is Powershell, we have -NoExit:
"commandline": "powershell.exe -NoExit \"<Your command goes here>\"",
If the profile is CMD, we have the /k flag:
"commandline": "cmd /k \"<Your command goes here>\"",
I didn't find the wsl equivalent.
Related:
- Windows Terminal: run CLI command on start up
- How can I open WSL terminal with a command without it automatically closing?
- How to start WSL in windows terminal programmatically and run command
Windows Terminal version: 1.15.3465.0 - Wsl 2 running Debian bullseye 11.6
-cbash will not remain once the command line passed is executed (similar to running the line withexecI think).--rcfileis the only workaround I can think of that fulfill your need. – Tom Yan Jan 11 '23 at 12:05export foobar=$(ls -a); echo $foobar; exec bash?foobarwould then be available in the replacement shell. – NotTheDr01ds Jan 11 '23 at 13:11/fcmd flag and-NoExitpowershell option are doing exactly what I need, so yes it is definitely related towsl. I will look into--rcfilebut using a file is not really convenient. Thanks! – 4wk_ Jan 11 '23 at 13:24-NoExit, it cannot change the way how bash runs a command or determine whether the shell will exit, unless bash itself has a switch for you to change how it works (so that e.g. wsl can translate its-NoExitto a switch that gets passed to bash). Put it in another way, even if wsl allows you to prevent itself from quitting, you'll just get an "empty" terminal or whatever that has no shell / process running. – Tom Yan Jan 11 '23 at 13:42terminal start wsl => wsl start bash => bash run commandsandterminal start powershell (or cmd) => powershell (or cmd) run commands? – 4wk_ Jan 11 '23 at 14:55