Bash, appending text to the end of a variable?
This question already has an answer here:
Append like:
file="${file}ins.b"
If you don't use braces then it treats fileins
as a variable and expands it. Since, it's probably not set it just prints .b
.
Related: When do we need curly braces in variables using Bash?
In bash you can also reference variables like ${file}
. So this should work for you:
file="${file}ins.b"
You don't need to expand the old value at all; bash has a +=
operator:
file+="ins.b"
链接地址: http://www.djcxy.com/p/29128.html
上一篇: Bash:用perl动态替换
下一篇: Bash,将文本追加到变量的末尾?