4
#!/bin/sh
arr=(
a
b
c
)
sed "s/abc/${arr[@]}/" file
SH -x this_script.sh顯示錯誤結果:
+ 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
有已經雙引號在這個腳本中,爲什麼需要聲明一個變量使其工作:
x=${arr[@]}
sed "s/abc/$x/" file