Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.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
Shell sed命令中的${arr[@]}_Shell_Sed - Fatal编程技术网

Shell sed命令中的${arr[@]}

Shell sed命令中的${arr[@]},shell,sed,Shell,Sed,sh-x this_script.sh显示带有错误的结果: #!/bin/sh arr=( a b c ) sed "s/abc/${arr[@]}/" file 应该是: + arr=(a b c) + sed s/abc/a b c/ file sed: -e expression #1, char 5: unterminated `s' command 此脚本中已经有双引号,为什么需要声明一个变量才能使其工作: + sed 's/abc/a b c/' fil

sh-x this_script.sh显示带有错误的结果:

#!/bin/sh

arr=(
    a
    b
    c
)
sed "s/abc/${arr[@]}/" file
应该是:

+ arr=(a b c)
+ sed s/abc/a b c/ file
sed: -e expression #1, char 5: unterminated `s' command
此脚本中已经有双引号,为什么需要声明一个变量才能使其工作:

+ sed 's/abc/a b c/' file

您可以使用
${arr[*]}
而不是
${arr[@]}
将其视为单个字符串:

 x=${arr[@]}
 sed "s/abc/$x/" file
sed“s/abc/${arr[*]}/”
sed "s/abc/${arr[*]}/" <<< "abc"

a b c