本文介绍了如何在bash脚本中连接变量和字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在bash脚本中连接变量和字符串?
How to concat variable and string in bash script ?
val1 = Variable1 + "any string "例如:
val1 = $i + "-i-*"其中i = 3月24日
where i = 24thMarch
我想要回声val1:
24thMarch-i-*什么是合适的解决方案?
What is proper proper to get the solution ?
推荐答案默认情况下,字符串在外壳中是串联的.
Strings are concatenated by default in the shell.
value="$variable"text"$other_variable"通常认为将变量扩展用双引号引起来是一种很好的做法.
It's generally considered good practice to wrap variable expansions in double quotes.
您也可以执行以下操作:
You can also do this:
value="${variable}text${other_variable}"大括号在处理变量名和字符串的混合体时很有用.
The curly braces are useful when dealing with a mixture of variable names and strings.
请注意,作业中=周围不应有空格.
Note that there should be no spaces around the = in an assignment.
更多推荐
如何在bash脚本中连接变量和字符串
发布评论