1、# path=" bb"
2、# sed -nr "/^.*set.*path/s#(.*set.*path)(.*)(;.*)#\1$path\3#p" ./test
set $path bb;
3、# sed -ir "/^.*set.*path/s#(.*set.*path)(.*)(;.*)#\1$path\3#" ./test
4、# cat test
set $path aa;
5、# sed -i -r "/^.*set.*path/s#(.*set.*path)(.*)(;.*)#\1$path\3#" ./test
6、# cat test
set $path bb;
1、給path變量賦值
2、使用sed -nr "/.../s#...#...#p" 組合僅將修改的行打印從結果查看可以修改成功
3、使用sed -ir參數修改test文件
4、cat該文件,發現未修改。
5、使用sed -i -r參數修改test文件
6、cat該文件,發現已修改成功