sed 变量替换

echo $(pwd)$0 | sed "s/\/1.sh//" | sed "s/\.//" | sed "s/\/\//\//" | sed "s,^$(pwd)/home,\/home,g"

变量替换,前面要加正则


C=$(echo $(pwd)$0 | sed "s/\/1.sh//" | sed "s/\.//" | sed "s/\/\//\//" | sed "s,^$(pwd)/home,$(pwd)/sasa,g")


变量替换变量也可以


b=bbbb/bbbb
在进行替换呢?


点击(此处)折叠或打开

  1. echo "aaaa"| sed -n "s/aaaa/$b/p"

  2. sed:-e expression #1, char 13: unknown optionto `s



?如何解决呢;$b中的/被用作了s命令匹配
将sed中/ 替换成# 就行了


点击(此处)折叠或打开

  1. echo "aaaa"| sed -n "s#aaaa#$b#p"

  2. bbbb/bbbb


你可能感兴趣的:(sed,变量替换)