Escaping curly braces in Bamboo In Atlassian Bamboo, in script tasks you can use special Bamboo environment variables e.g. for current build number

${bamboo.buildNumber}


Now I have the impression if I have a code piece  like ${VAR} which I want to pass to other context, Bamboo's templating logic will kick in and render this part as an empty string.

Proof:

echo "my foo ${VAR}!"


Output:

01-Feb-2018 20:47:58    my foo !


Is there a way to escape curly braces in this context?

What I have tried:


googling it: nope
${{VAR}} - bad substution error
$\{VAR\} leads to exactly same output as it escaped which I do not want to have either.


UPDATE from comments - making sure there is no existing variable being just empty.

Input:

echo "my foo random ${RANDOM_VAR_ABCFOO}!"
echo "my foo random with prefix ${bamboo.RANDOM_VAR_ABCFOO}!"


Output:

Bamboo 5.13.1 

02-Feb-2018 10:26:11    my foo random !
02-Feb-2018 10:26:11    /home/bambooagent/temp/FOO-JOB1-4-ScriptBuildTask-3130782940072218698.sh: 2: /home/bambooagent/temp/FOO-JOB1-4-ScriptBuildTask-3130782940072218698.sh: Bad substitution


Bamboo 6.3.0

02-Feb-2018 10:22:02    my foo random !
02-Feb-2018 10:22:02    /data/bamboo-agent/temp/FOO-JOB1-24-ScriptBuildTask-7913400670965638044.sh: line 2: my foo random with prefix ${bamboo.RANDOM_VAR_ABCFOO}!: bad substitution
I don't know the inner of bamboo, but I assume it works like a bash script.

What happens is that variables are replaced before execution, in bash that would be echo "echo $VAR" &gt; test.sh and test.sh will only contain "echo" because VAR is replaced by it's value before the command is executed.
If you want test.sh to contain echo $VAR you have to tell bash to ignore the replacement on the first call by escaping the $ sign:

echo "echo \$var" &gt; test.sh will give echo  $VAR in the file.

In the same note, the notation ${VAR} and $VAR are the same, using braces is a good practice when you do concatenation like in echo "Size is ${VAR}Kb" as without the braces like this $VARKb bash would try to find a variable named VARKb and return an empty value.

To address PrestonM different behavior, I assume there's either
 - the fact running under windows with the powershell interpreter doesn't behave the same
 - or just that bamboo has a special case for variables prefixed with bamboo. and as such escape them.

If someone want to test you may try:

echo "${VAR}"
echo "${bamboo.VAR}"
echo "\${VAR}"


and edit the results in this answer.