Escape $ Passing Variable to Second Script

Mindwatering Incorporated

Author: Tripp W Black

Created: 11/14/2023 at 11:40 AM

 

Category:
Linux
Other

Issue:
Have variable in BASH script.
example:
$myvar="textstringwith$sign"

If we escape it with single quotes or backslash it works to read into that first script correctly, but when passing to the second BASH script if fails.
If we double escape, then we nullify for the first script.
In other words, both of the tries below do not work:
$myvar = ''textstringwith$sign'' (this is two single quotes, not a double quote)
$myvar = "textstringwith\\$sign"


Solution:
Do one of each type of escape.
$myvar = 'textstringwith\$sign'


The first BASH script parse sees the variable as:
textstringwith\$sign

The second BASH script sees the passed variable as:
textstringwith$sign



previous page