Answers: <p>I don't know the inner of bamboo, but I assume it works like a bash script.</p>
  
  <p>What happens is that variables are replaced before execution, in bash that would be <code>echo "echo $VAR" &gt; test.sh</code> and test.sh will only contain "echo" because VAR is replaced by it's value before the command is executed.<br>
  If you want test.sh to contain <code>echo $VAR</code> you have to tell bash to ignore the replacement on the first call by escaping the $ sign:</p>
  
  <p><code>echo "echo \$var" &gt; test.sh</code> will give <code>echo  $VAR</code> in the file.</p>
  
  <p>In the same note, the notation <code>${VAR}</code> and <code>$VAR</code> are the same, using braces is a good practice when you do concatenation like in <code>echo "Size is ${VAR}Kb"</code> as without the braces like this <code>$VARKb</code> bash would try to find a variable named <code>VARKb</code> and return an empty value.</p>
  
  <p>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 <code>bamboo.</code> and as such escape them.</p>
  
  <p>If someone want to test you may try:</p>
  
  <pre><code>echo "${VAR}"
  echo "${bamboo.VAR}"
  echo "\${VAR}"
  </code></pre>
  
  <p>and edit the results in this answer.</p>
  
Answers: CC BY-SA 3.0
Answers: 2018-02-02T10:25:43.593Z
Answers: 2018-02-02T10:31:08.177Z
Answers: 2018-02-02T10:31:08.177Z
Answers: Tensibai
Answers: <p>If your variable is <strong>not</strong> declared in Bamboo (either by injections, build/deploy variables etc.) it will <strong>not</strong> inject the variable and will use the string as is. It should only render the variable as an empty string if that is the value you set for that particular variable. As an example, my build plan has the following variables:</p>
  
  <pre><code>Variable Name    Value
  version.major    1
  version.minor    12
  </code></pre>
  
  <p>In my build plan, I have the following script job:</p>
  
  <pre><code>echo "${bamboo.substituteVar}"
  echo "${bamboo.version.major}"
  echo "${bamboo.version.minor}"
  </code></pre>
  
  <p>In my logs, the output will be:</p>
  
  <blockquote>
    <p>C:\Users\TestUser\bamboo-home\xml-data\build-dir\12345678\MANG-TC-TBV>echo
    "${bamboo.substituteVar}"</p>
    
    <p>"${bamboo.substituteVar}"</p>
    
    <p>C:\Users\TestUser\bamboo-home\xml-data\build-dir\12345678\MANG-TC-TBV>echo "1"</p>
    
    <p>"1"</p>
    
    <p>C:\Users\TestUser\bamboo-home\xml-data\build-dir\12345678\MANG-TC-TBV>echo "12"</p>
    
    <p>"12"</p>
  </blockquote>
  
  <p>As long as your variables and namespaces are unique and descriptive for the plan you are working on, you should not have any issues with name conflicts. If it is replacing it with an empty string, my guess is that you may have that variable created somewhere in Bamboo, but no value assigned to it. </p>
  
Answers: CC BY-SA 3.0
Answers: 2018-02-01T23:27:33.447Z
Answers: Do you mean my answer? I guess what I was trying to convey was that his assumption that bamboo replaces undeclared variables with empty values is wrong.
Answers: Preston Martin
Answers: CC BY-SA 3.0
Answers: 2018-02-01T23:32:19.117Z
Answers: My bad, I did miss the first case, it would have been better without the bamboo prefix to showcase the same usage as question state, first step being écho ${VAR}
Answers: Tensibai
Answers: CC BY-SA 3.0
Answers: 2018-02-01T23:35:02.653Z
Answers: (I wouldn't be surprised bamboo parser only takes special behavior on bamboo. Prefixed variables)
Answers: Tensibai
Answers: CC BY-SA 3.0
Answers: 2018-02-01T23:37:23.380Z
Answers: Yep that's exactly what it does. Even if you prefix it with Bamboo, if that variable doesn't exist, it won't replace it with anything.
Answers: Preston Martin
Answers: CC BY-SA 3.0
Answers: 2018-02-02T09:30:21.163Z
Answers: thanks - please share which version of Bamboo do you have? see update above - Bamboo 5.13.1 and 6.3.0 behaves not the way you suggest. Maybe there is some setting for parsing and substituting variables?
Answers: Ta Mu
Answers: CC BY-SA 3.0
Answers: 2018-02-01T21:17:09.967Z
Answers: 2018-02-01T21:57:19.240Z
Answers: 2018-02-01T21:57:19.240Z
Answers: Preston Martin
Body: <p>In Atlassian Bamboo, in script tasks you can use special Bamboo environment variables e.g. for current build number</p>
  
  <pre><code>${bamboo.buildNumber}
  </code></pre>
  
  <p>Now I have the impression if I have a code piece  like <code>${VAR}</code> which I want to pass to other context, Bamboo's templating logic will kick in and render this part as an empty string.</p>
  
  <p>Proof:</p>
  
  <pre><code>echo "my foo ${VAR}!"
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>01-Feb-2018 20:47:58    my foo !
  </code></pre>
  
  <p>Is there a way to escape curly braces in this context?</p>
  
  <p>What I have tried:</p>
  
  <ul>
  <li>googling it: nope</li>
  <li><code>${{VAR}}</code> - bad substution error</li>
  <li><code>$\{VAR\}</code> leads to exactly same output as it escaped which I do not want to have either.</li>
  </ul>
  
  <p><em>UPDATE from comments</em> - making sure there is no existing variable being just empty.</p>
  
  <p>Input:</p>
  
  <pre><code>echo "my foo random ${RANDOM_VAR_ABCFOO}!"
  echo "my foo random with prefix ${bamboo.RANDOM_VAR_ABCFOO}!"
  </code></pre>
  
  <p>Output:</p>
  
  <p><em>Bamboo 5.13.1</em> </p>
  
  <pre><code>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
  </code></pre>
  
  <p><em>Bamboo 6.3.0</em></p>
  
  <pre><code>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
  </code></pre>
  
Comments: CC BY-SA 3.0
Comments: 2018-02-01T23:27:58.830Z
Comments: Let me see if I got it rigjt: bamboo replace your bash script variables before runing the script,? If yes try to escape the dollar signe the braces are there to help parsing the Var name and won't be interpreted after an escaped $, for the note $VAR is the same as ${VAR}, the brace are useful when concatenating to precise which part is the var
Comments: Tensibai
Comments: CC BY-SA 3.0
Comments: 2018-02-01T23:36:40.500Z
Comments: Previous comment is badly written but I hope you get the idea, it's too late to try to correct on phone :)
Comments: Tensibai
Comments: CC BY-SA 3.0
Comments: 2018-02-02T09:48:52.623Z
Comments: May you try `echo "\${VAR}"`?
Comments: Tensibai
Comments: CC BY-SA 3.0
Comments: 2018-02-02T09:56:52.230Z
Comments: Maybe of use: https://stackoverflow.com/a/45918619/3627607
Comments: Tensibai
Comments: CC BY-SA 3.0
Comments: 2018-02-02T10:13:25.090Z
Comments: works! please share your solution ;-) THANK YOU
Comments: Ta Mu
Comments: CC BY-SA 3.0
Comments: 2018-02-02T10:20:09.970Z
Comments: Which one ? escaping the $ sign or the SO answer ? (I think you may self answer yourself, I may add precision if needed)
Comments: Tensibai
Comments: CC BY-SA 3.0
Comments: 2018-02-02T10:20:41.097Z
Comments: "\${VAR}" works
Comments: Ta Mu
Comments: CC BY-SA 3.0
Comments: 2018-02-02T10:21:01.933Z
Comments: Ok so I think that's a simple bash variable replacement problem
Comments: Tensibai
Tags: <continuous-integration><bamboo>
Title: Escaping curly braces in Bamboo
UserDisplayName: Ta Mu
ThreadText: # Escaping curly braces in Bamboo
  
  (Asked by: username_0 on 2018-02-01)
  
  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
  
  ```
  
  **Tags:** continuous-integration, bamboo
  
  > **Comments:**
  > **username_1**: Let me see if I got it rigjt: bamboo replace your bash script variables before runing the script,? If yes try to escape the dollar signe the braces are there to help parsing the Var name and won't be interpreted after an escaped $, for the note $VAR is the same as ${VAR}, the brace are useful when concatenating to precise which part is the var  
  > **username_1**: Previous comment is badly written but I hope you get the idea, it's too late to try to correct on phone :)  
  > **username_1**: May you try `echo "\${VAR}"`?  
  > **username_1**: Maybe of use: https://stackoverflow.com/a/45918619/3627607  
  > **username_0**: works! please share your solution ;-) THANK YOU  
  > **username_1**: Which one ? escaping the $ sign or the SO answer ? (I think you may self answer yourself, I may add precision if needed)  
  > **username_0**: "\${VAR}" works  
  > **username_1**: Ok so I think that's a simple bash variable replacement problem  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-02-02. Score: 1 | Accepted answer
  
  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" > 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" > 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.
  
  
  ---
  
  ### Answer by username_2 on 2018-02-01. Score: 0
  
  If your variable is **not** declared in Bamboo (either by injections, build/deploy variables etc.) it will **not** inject the variable and will use the string as is. It should only render the variable as an empty string if that is the value you set for that particular variable. As an example, my build plan has the following variables:
  
  ```
  Variable Name    Value
  version.major    1
  version.minor    12
  
  ```
  
  In my build plan, I have the following script job:
  
  ```
  echo "${bamboo.substituteVar}"
  echo "${bamboo.version.major}"
  echo "${bamboo.version.minor}"
  
  ```
  
  In my logs, the output will be:
  
  > C:\Users\TestUser\bamboo-home\xml-data\build-dir\12345678\MANG-TC-TBV>echo
  > "${bamboo.substituteVar}"
  >
  > "${bamboo.substituteVar}"
  >
  > C:\Users\TestUser\bamboo-home\xml-data\build-dir\12345678\MANG-TC-TBV>echo "1"
  >
  > "1"
  >
  > C:\Users\TestUser\bamboo-home\xml-data\build-dir\12345678\MANG-TC-TBV>echo "12"
  >
  > "12"
  
  As long as your variables and namespaces are unique and descriptive for the plan you are working on, you should not have any issues with name conflicts. If it is replacing it with an empty string, my guess is that you may have that variable created somewhere in Bamboo, but no value assigned to it.
  
  > **Comments:**
  > **username_2**: Do you mean my answer? I guess what I was trying to convey was that his assumption that bamboo replaces undeclared variables with empty values is wrong.  
  > **username_1**: My bad, I did miss the first case, it would have been better without the bamboo prefix to showcase the same usage as question state, first step being écho ${VAR}  
  > **username_1**: (I wouldn't be surprised bamboo parser only takes special behavior on bamboo. Prefixed variables)  
  > **username_2**: Yep that's exactly what it does. Even if you prefix it with Bamboo, if that variable doesn't exist, it won't replace it with anything.  
  > **username_0**: thanks - please share which version of Bamboo do you have? see update above - Bamboo 5.13.1 and 6.3.0 behaves not the way you suggest. Maybe there is some setting for parsing and substituting variables?  
  
  ---
  
  