0

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.

Rorschach
  • 31,301
  • 5
  • 78
  • 129

2 Answers2

1

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
Andreas Louv
  • 46,145
  • 13
  • 104
  • 123
  • 1
    @jenesaisquoi One hack, not recommenced could be to grep the value from `env`: `env | grep -P '(?<=ProgramFiles\(x86\)=).*$'`, or `env | awk -F= '$1=="ProgramFiles(x86)"{print $2}'` – Andreas Louv Jun 08 '16 at 06:53
1

Use the Windows command processor:

PFX86="$(cmd //c 'echo %ProgramFILES(x86)%')"