my env var is IntelliJ IDEA Community Edition. using win10 gitbash.
IntelliJ IDEA Community Edition C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.3.2\bin
How to do echo? This is not working:
>echo $IntelliJ IDEA Community Edition
>echo ($IntelliJ IDEA Community Edition)
>echo $%IntelliJ IDEA Community Edition%
>echo %IntelliJ IDEA Community Edition%
>echo '$%IntelliJ IDEA Community Edition%'
>echo 'IntelliJ IDEA Community Edition'
Other env vars without spaces like QT_SCALE_FACTOR_ROUNDING_POLICY do work using
echo $QT_SCALE_FACTOR_ROUNDING_POLICY
EDIT with help of Charles Duffy:
i used env | grep IDEA and i did get all the stuff with 'IDEA' including the path that i need:
$ env | grep IDEA
IntelliJ IDEA Community Edition=C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.3.2\bin;
PATH=/c/Users/erjan/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/erjan/bin:/c/Program Files/Eclipse Foundation/jdk-11.0.12.7-hotspot/bin:/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/c/Windows/System32/OpenSSH:/c/Program Files (x86)/Microsoft SQL Server/150/DTS/Binn:/c/Program Files/PuTTY:/c/Program Files/Calibre2:/c/Program Files/nodejs:/cmd:/c/Program Files/Docker/Docker/resources/bin:/c/ProgramData/DockerDesktop/version-bin:/c/python38/Scripts:/c/python38:/c/Users/erjan/AppData/Local/Microsoft/WindowsApps:/c/Program Files/Azure Data Studio/bin:/c/Users/erjan/AppData/Local/Programs/Microsoft VS Code/bin:/c/Users/erjan/AppData/Roaming/npm:/c/Program Files/JetBrains/IntelliJ IDEA Community Edition 2020.3.2/bin:/c/kafka_2.12-2.8.0/bin/windows:/usr/bin/vendor_perl:/usr/bin/core_perl
ORIGINAL_PATH=/mingw64/bin:/usr/bin:/c/Users/erjan/bin:/c/Program Files/Eclipse Foundation/jdk-11.0.12.7-hotspot/bin:/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/c/Windows/System32/OpenSSH:/c/Program Files (x86)/Microsoft SQL Server/150/DTS/Binn:/c/Program Files/PuTTY:/c/Program Files/Calibre2:/c/Program Files/nodejs:/cmd:/c/Program Files/Docker/Docker/resources/bin:/c/ProgramData/DockerDesktop/version-bin:/c/python38/Scripts:/c/python38:/c/Users/erjan/AppData/Local/Microsoft/WindowsApps:/c/Program Files/Azure Data Studio/bin:/c/Users/erjan/AppData/Local/Programs/Microsoft VS Code/bin:/c/Users/erjan/AppData/Roaming/npm:/c/Program Files/JetBrains/IntelliJ IDEA Community Edition 2020.3.2/bin:/c/kafka_2.12-2.8.0/bin/windows
CodePudding user response:
Since you're on Windows and don't have procfs, the easiest way to retrieve the full environment is with env
.
Note that whether the shell strips environment variables with names that don't match legal shell variable names from the environment (thus also making them unavailable to tools like env
) is implementation-defined; the POSIX sh standard makes it legal for shells to strip such names, but also legal to leave them in, so whether this works can vary by version.
idea=$(env | sed -rne '/^IntelliJ IDEA Community Edition=/ { s/^[^=] =//p }')
if [[ $idea ]]; then
echo "Found IntelliJ at: $idea"
else
echo "Could not find IntelliJ"
fi