Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash Jenkins项目中${my_variable}和$my_variable之间的差异_Bash_Shell_Jenkins - Fatal编程技术网

Bash Jenkins项目中${my_variable}和$my_variable之间的差异

Bash Jenkins项目中${my_variable}和$my_variable之间的差异,bash,shell,jenkins,Bash,Shell,Jenkins,在Jenkins项目中使用变量时,以下两者之间是否存在差异: node index.js${arg} 这是: node index.js$arg 其中arg是项目的参数 更新: 有趣的是,这并不是詹金斯特有的 我认为这个问题应该保留下来,因为其他人可能会认为这与Jenkins有关。这实际上是一种标准的shell语法 更容易操作变量/将变量的内容连接到其他变量名中。e、 g ${foo}bar 您还可以使用{}执行其他字符串操作: STRING="This is a string" echo $

在Jenkins项目中使用变量时,以下两者之间是否存在差异:

node index.js${arg}

这是:

node index.js$arg

其中arg是项目的参数

更新: 有趣的是,这并不是詹金斯特有的


我认为这个问题应该保留下来,因为其他人可能会认为这与Jenkins有关。

这实际上是一种标准的shell语法

更容易操作变量/将变量的内容连接到其他变量名中。e、 g

${foo}bar
您还可以使用
{}
执行其他字符串操作:

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

我还发现带有
{}
的变量可以更好地阅读,但这是个人偏好


这里的一般答案是:

在Jenkins项目的上下文中,除了风格问题之外,不需要它

在shell可能无法确定变量名结尾的情况下,大括号非常有用。例如,如果变量名为
this
,则如果命令为

echo "${this}isatest"
此外,当您想利用Bash的功能时,也需要它们。

可能重复的