Adrian Lynch
Adrian Lynch

Reputation: 8494

Difference between ${my_variable} and $my_variable in a Jenkins project

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.

Upvotes: 7

Views: 2533

Answers (2)

Greg Tarsa
Greg Tarsa

Reputation: 1642

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.

Upvotes: 3

Clarkie
Clarkie

Reputation: 7550

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?

Upvotes: 3

Related Questions