Shell sed命令中的${arr[@]}
sh-x this_script.sh显示带有错误的结果: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
#!/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