1

I want to create a shortcut which starts Windows Terminal with Windows Subsystem for Linux (WSL) and exports the path to my arm-gcc compiler files. Looking over other posts on SO, I've gotten this in the target of the shortcut:

wt.exe wsl.exe ~  -d Ubuntu bash -c export PATH="/mnt/m/ARM/gcc-arm/bin:$PATH"

This, however, does not work as an instance of Windows Terminal starts up and then exits without providing me an error. Trying to do variations like

wt.exe wsl.exe ~  -d Ubuntu bash -export "PATH="/mnt/m/ARM/gcc-arm/bin:$PATH""

And so on did not help, I just get errors back. How would this be done?

Henke
  • 4,445
  • 3
  • 31
  • 44
Nick S.
  • 168
  • 1
  • 12

1 Answers1

1

From PowerShell:

wt wsl ~ -d Ubuntu -e sh -c 'PATH="/mnt/m/ARM/gcc-arm/bin:$PATH" bash'

From CMD (which should be what you need for a shortcut):

wt wsl ~ -d Ubuntu -e sh -c ^"PATH=\^"/mnt/m/ARM/gcc-arm/bin:$PATH\^" bash^"

... should work. That:

  • Starts the POSIX-equivalent shell
  • Then has the first shell start the bash shell with the updated PATH
NotTheDr01ds
  • 15,620
  • 5
  • 44
  • 70
  • Thank you for your reply! I've tried 'wt wsl ~ -d Ubuntu -e sh -c 'PATH="/mnt/m/ARM/gcc-arm/bin:$PATH bash'' and I get 'sh: 1: PATH=/mnt/m/ARM/gcc-arm/bin:$PATH bash: not found' back. Do you not need to close the quotation marks? I see only the opening ' " '? I've also tried the following: 'wt wsl ~ -d Ubuntu -e sh -c 'PATH="/mnt/m/ARM/gcc-arm/bin:$PATH" bash'' but that returns 'bash': 1: Syntax error: Unterminated quoted string'. – Nick S. Mar 17 '22 at 03:19
  • Also, is there anywhere I can find more documentation on types of arguments I can pass to the shortcuts? My google-fu has failed me in that regard =\ – Nick S. Mar 17 '22 at 03:22
  • @NickStpn You're absolutely correct - I missed the closing double-quote around the PATH somehow. Since I copied/pasted it, I can only guess I backspaced over it or something :-/. But then we run into your second problem. And that's probably because my original example was from PowerShell, and I forgot you need the CMD-quoting since you are creating a shortcut. Quoting rules are trickier in CMD, but I think I got it right -- It works on my copy/paste into CMD, at least. – NotTheDr01ds Mar 17 '22 at 03:56
  • As for passing arguments, I'm assuming you mean to the WSL command? Or do you mean arguments to the actual shortcut? We're really only using the `-e` argument to execute the `sh` command, then we're using `-c ` to execute those commands in the shell. – NotTheDr01ds Mar 17 '22 at 04:01
  • I get the following when I use the modified string: `sh: 1: ^PATH=^/mnt/m/ARM/gcc-arm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program: not found [process exited with code 127]` I'm not sure if this issue is because I'm calling onto Windows Terminal vs CMD? I'll play some more with it tomorrow. The easier solution to all of this is to just probably include the necessary command in my WSL's `.bashrc`, but I was really curious on how to make custom shortcuts for applications. – Nick S. Mar 17 '22 at 04:22
  • I actually meant arguments and formatting with regards to the actual shortcut target. Do they just accept any typical command-line arguments? P.S. For some reason, it seems I can't refer to you when I type `@NotTheDr01ds` – Nick S. Mar 17 '22 at 04:25