[CentOS] Special characters in bash strings

Thu Jul 7 01:41:14 UTC 2022
H <agents at meddatainc.com>

I have run into a bash variable string problem that I think I have nailed down to the variable string containing a tilde (~). Not sure if my conclusion is correct and could use some help.

To make a long(er) story short, an associative array variable was created:

p[work_path]="~/projects/test/"

and referenced in the following format in the shell script:

"${p[work_path]}"

To my consternation this worked fine in some places but not in others. I tried to use the above construct when piping output, as part of a file reference when calling psql from the command line and when referencing an xslt file with xsltproc.

In some places it worked, in others it did not but when I substituted the variable reference above with the path in clear text itself it then worked.

It looks like there are some nuances on variable substitution that I have yet to learn, perhaps tied to the use of the tilde since using the variable p[work_path]="/home/user/projects/test/" seemed to work in all places.

Pointers welcome!