开发者

Bash and variables

Scenario

$ VAR1=test

$ VAR2=testing

$ VAR3=$VAR1_$VAR2

$ echo $VAR3

testing

I expected "test_testing" as the output. Why its not working? How to output in "test_testing" format? (make $VAR1_$VAR2 work)

Does it interprets VAR3=$VAR1_$VA开发者_高级运维R2 as VAR3=$(VAR1_$VAR2) ?


Try

$ echo ${VAR1}_${VAR2}

Without the braces, it parses the combination as ${VAR1_}${VAR2}. Since you do not have a $VAR1_ variable defined, you see only the value of $VAR2.

You can see this if you define a variable $VAR1_:

$ VAR1_=another
$ echo $VAR1_$VAR2
anothertesting


try:

VAR3="$VAR1"_"$VAR2"

it interprets VAR3=$VAR1_$VAR2 as $VAR1_ + $VAR2 --- there is no variable named $VAR1_

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜