如何在Shell脚本中将值附加到变量 [英] how to append a value to a variable in shell script
本文介绍了如何在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
这篇关于如何在Shell脚本中将值附加到变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文