Search code examples
windowsbashenvironment-variablesmsys2

Expand bash environment variable containing '('


Using bash from msys2 on windows 10, I can't seem to set a variable to a windows environment variable containing parens, ie '(', in a bash script. For example,

p86="$PROGRAMFILES(x86)"

doesn't work, it expands the env variable $PROGRAMFILES. I've tried escaping with backslashes, ie. "$PROGRAMFILES\(x86\)" but that doesn't work. Is there a way around this in bash? or are parens just not allowed in expanded variables?. All of the windows variables are available in the process environment.


Solution

  • Usually you would use ${..} to dereference a variable, eg:

    echo "${a}bc"
    

    will print the variable $a and then literal bc.

    Try:

    p86="${PROGRAMFILES(x86)}"
    

    Alternative you should check the output of env to see if the variable is present:

    env | grep PROGRAM