Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何在bash中将逗号(,)用作变量的值_Linux_Bash_Unix - Fatal编程技术网

Linux 如何在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

我想在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
但是,强烈建议引用您的变量,如

echo "$string"
即使是这个
IFS=,
也可以使用带引号的变量:

IFS=,
echo "$string"
xyz,pqr
@然而,问题是:你究竟为什么要把
如果设置为
?您很可能在脚本的某个地方全局设置了
IFS
,这不好!修正你的脚本!
IFS=,
echo "$string"
xyz,pqr