How do I get the absolute path to a given binary and store it to a variable?
What is the equivalent to the following for Linux Bash in Windows Powershell?
user@disp985:~$ path=`which gpg`
user@disp985:~$ echo $path
/usr/bin/gpg
user@disp985:~$
user@disp985:~$ $path
gpg: keybox '/home/user/.gnupg/pubring.kbx' created
gpg: WARNING: no command supplied. Trying to guess what you mean ...
gpg: Go ahead and type your message ...
In Windows Powershell, there's Get-Command
, but the output is hardly trivial to parse programmatically for a script.
PS C:\Users\user> Get-Command gpg.exe
CommandType Name Version Source
----------- ---- ------- ------
Application gpg.exe 2.2.28.... C:\Program Files (x86)\Gpg4win\..\GnuP...
PS C:\Users\user>
How can I programmatically determine the full path to a given binary in Windows Powershell, store it to a variable, and execute it?