我有一个 for 循环,里面有两个 sed 命令来编辑不同的文件。我的问题是第二个 sed 应该只编辑名为 aaa 的文件,但我收到错误 sed 无法编辑“不是常规文件”。
for file in $directory
do [-e "$file"] || continue
sed -i 's/hello/hello1/g' "$file"
sed -i 's/hallo/hello12/g' [[ "$file" ~ aaa ]]
done
答案 0 :(得分:0)
建议更换
[-e "$file"]
与
[ -e "$file" ]
和
sed -i 's/hallo/hello12/g' [[ "$file" ~ aaa ]]
与
[[ "$file" =~ ^aaa$ ]] && sed -i 's/hallo/hello12/g' "$file"