sed替换变量【原创】

使用以下方法不行

sed -i 's/\$this_year/\$next_year/g' schema.xml.$next_year

使用双引号,变量外边不要使用小括号要是大括号

#!/bin/bash
this_year=$(date +%Y)
next_year=$(date -d next-year +%Y)

sed -i "s/${this_year}/${next_year}/g" schema.xml.$next_year
sed -i "s/${this_year}/${next_year}/g" rule.xml.$next_year 
sed -i "s/${this_year}/${next_year}/g" server.xml.$next_year

转载请注明出处!

原文地址:https://www.cnblogs.com/paul8339/p/15723797.html