Linux 如何在bash中将逗号(,)用作变量的值
我想在bash中使用逗号作为变量的值 代码:Linux 如何在bash中将逗号(,)用作变量的值,linux,bash,unix,Linux,Bash,Unix,我想在bash中使用逗号作为变量的值 代码: 请帮忙,谢谢这对我来说很好 #!/bin/sh a=xyz y=pqr seprator=',' string=$a$seprator$y echo $string [root@HOFVW2090 data]# ./test.sh xyz,pqr 必须将IFS设置为逗号。请参见此示例: IFS=, echo $string xyz pqr unset IFS echo $string xyz,pqr 但是,强烈建议引用您的变量,如 ech
请帮忙,谢谢这对我来说很好
#!/bin/sh
a=xyz
y=pqr
seprator=','
string=$a$seprator$y
echo $string
[root@HOFVW2090 data]# ./test.sh
xyz,pqr
必须将
IFS
设置为逗号。请参见此示例:
IFS=,
echo $string
xyz pqr
unset IFS
echo $string
xyz,pqr
但是,强烈建议引用您的变量,如
echo "$string"
即使是这个IFS=,
也可以使用带引号的变量:
IFS=,
echo "$string"
xyz,pqr
@然而,问题是:你究竟为什么要把如果设置为,
?您很可能在脚本的某个地方全局设置了IFS
,这不好!修正你的脚本!
IFS=,
echo "$string"
xyz,pqr