![]() ![]() ![]() In your use-case, however, you mentioned that this wasn't a viable option. If the need is to get a variable injected into the new shell, then export'ing the variable before running the new shell may be the best bet. I'd recommend using Here-strings: wsl -e bash -c bash -rcfile <(echo 'source ~/.bashrc foobar=$(ls most users, however, try the following first to see if it meets your needs: wsl -e bash -c \"export foobar=$(ls -a) echo $foobar exec bash\"" If you were doing this from PowerShell, the quoting/escaping rules would be a bit different. So keep an eye out for any "gotchas" if your command fails, and test it from the Command Prompt ( CMD) profile first to see errors reported. Keep in mind that Windows Terminal profiles seem to use CMD quoting and escaping rules. You mentioned that you'd like to avoid the use of a file, though, which can also be accomplished (courtesy a WSL/WT-modified version of this SO answer and process-substitution )with: wsl -e bash -c "exec bash -rcfile <(echo 'source ~/.bashrc foobar=$(ls -a)')" 0 - Wsl 2 running Debian bullseye 11.6Īs mentioned by in the comments, the -rcfile option is probably the only real way to do this. How to start WSL in windows terminal programmatically and run command.How can I open WSL terminal with a command without it automatically closing?. ![]() Windows Terminal: run CLI command on start up.If the profile is CMD, we have the /k flag: "commandline": "cmd /k \"\"", viminfo echo the profile is Powershell, we have -NoExit: "commandline": "powershell.exe -NoExit \"\"", This workaround start another shell, so that does not work here: "commandline": "wsl -e bash -c \"foobar=`ls -a` echo $foobar exec bash\"", 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). 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). In Windows Terminal, you can create a profile and add some start-up command (through commandline option in settings.json file. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |