bash命令sed输出意外错误

时间:2017-04-06 14:06:12

标签: bash sed sh

我正在尝试使用sed替换文件中的单词。 在相同的bash脚本中,我使用命令:

sed -i "s/${list[$index]}/${phone}/g" $1

它在第一个函数上完美运行,但是我写的第二个函数:

sed -i "s/${list[$index]}/${zipcode}/g" $1

输出此错误:

sed: -e expression #1, char 0: no previous regular expression

我真的很绝望,我很确定这是我正在做的一个愚蠢的错误,但我无法解决它

1 个答案:

答案 0 :(得分:1)

When the first half of a sed substitute command is empty:

sed 's//foo/' <<< bar

It returns this error:

sed: -e expression #1, char 0: no previous regular expression

Therefore, as William Pursell commented, there's a value of the ${list[@]} array that's empty, or maybe $index is out of the array's range.