我有一个文件,我想用环境变量替换一些值。如果我将每个值分割为单独的sed
命令,则效果很好:
sed -i "s/NAME/$NAME/g" "file"
sed -i "s/REF/$REF/g" "file"
sed -i "s/REGION/$REGION/g" "file"
sed -i "s/BUCKET/$BUCKET/g" "file"
sed -i "s/BUCKET2/$BUCKET2/g" "file"
sed -i 's:FQDN:'`basename $(pwd)`':' "file"
但是如果我尝试类似的操作将不起作用:
sed -i "s/NAME/$NAME/g" "s/REF/$REF/g" "s/REGION/$REGION/g" "file"
它基本上只替换第一个值,然后在每个下一个值上失败:
sed: can't read s/REF/something/g: No such file or directory
用';'将命令分隔的命令分组:
sed -i -e "s/NAME/$NAME/g;s/REF/$REF/g;s/REGION/$REGION/g" "file"