6

Is there a difference when using variables in a Jenkins project between this:

node index.js ${arg}

and this:

node index.js $arg

Where arg is a parameter for the project.

Update: Interesting to note that it's not Jenkins-specific.

I think this question should remain as others may assume it's something to do with Jenkins.

Adrian Lynch
  • 8,237
  • 2
  • 32
  • 40
  • 1
    Possible duplicate of [bash: When do we need curly braces in variables?](http://stackoverflow.com/questions/8748831/bash-when-do-we-need-curly-braces-in-variables) – Mr. Llama Feb 24 '16 at 17:00

2 Answers2

3

In the context of your Jenkins project, it is not needed, except as a matter of style.

The braces are useful in those cases where the shell may not be able to determine the end of a variable name. For instance, if your variable is named this, then you would need the braces if your command was

echo "${this}isatest"

Also, you need them when you want to take advantage of Bash's Shell Parameter Expansions.

Greg Tarsa
  • 1,622
  • 13
  • 18
2

It's actually a standard shell syntax.

It's easier to manipulate variables / concatenate the contents of variables into other variable names. e.g.

${foo}bar

You can also perform additional string manipulation with the {}:

STRING="This is a string"
echo ${STRING// /_}

http://www.tldp.org/LDP/abs/html/string-manipulation.html

I also find variables with {} to read better but that's a personal preference.

Generic answer here: When do we need curly braces in variables using Bash?

Community
  • 1
  • 1
Clarkie
  • 7,490
  • 9
  • 39
  • 53