bash 连接字符串文字
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17729235/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Concatenate string literals
提问by Nick Rolando
I've seen a couple posts for this, like this one, but none are helping me in my particular situation.
我已经看过几个帖子,比如这个,但没有一个在我的特殊情况下帮助我。
scriptsPath="/var/db/gbi/scripts/"
echo "$scriptsPathawesome.csv";
I would expect this to echo /var/db/gbi/scripts/awesome.csv
我希望这能呼应 /var/db/gbi/scripts/awesome.csv
Instead I get .csv
相反,我得到 .csv
Seems like it thinks I'm trying to reference a variable named $scriptsPathawesome. How can I concatenate the $scriptsPathvariable to the "awesome.csv"string literal?
似乎它认为我正在尝试引用一个名为$scriptsPathawesome. 如何将$scriptsPath变量连接到"awesome.csv"字符串文字?
回答by Alfred Fazio
You need to surround your variable with curly braces like so:
你需要像这样用花括号包围你的变量:
scriptsPath="/var/db/gbi/scripts/"
echo "${scriptsPath}awesome.csv";

