如何在Shell脚本中将值附加到变量

问题描述:

我从属性中获取了一个变量值,并且能够在sh文件中进行访问.但我无法将另一个值附加到该变量.

I am getting a variable value from properties and I am able to access in sh file. but I am unable to append another value to that variable.

请提出建议.

$ echo "Build ID from properties:"$BUILD_ID
Build ID from properties: abcd_v6_c1

$ echo " num----------------" build_${BUILD_ID}.zip
.zip---------------- build_abcd_v6_c1

请提出如何附加 .zip 值.

似乎您有Windows 回车在您的 $ BUILD_ID 变量中.

It seems you have a Windows carriage return in your $BUILD_ID variable.

要进行检查,请尝试以下命令(回车符将显示为 ^ M ):

To check, try this command (the carriage return will be visible as a ^M) :

cat -A <<< "$BUILD_ID"

在终端中,您可以尝试此操作(要获取 ^ M 字符,请使用 CTRL + V + M ):

In your terminal,you can try this (to get the ^M char, use CTRL + V + M) :

$ BUILD_ID="585548979^M"
$ echo ${BUILD_ID}text

结果应为:

text48979

您可以使用Bash参数替换来清理变量:

You can clean your variable with a Bash parameter substitution :

$ ID=${BUILD_ID%$'\r'}
$ echo ${ID}text
585548979text