Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我使用 next 替换 linux 中的字符串:
sed -i 's/old-word/new-word/g' *.txt
问题是我的新词是宏,它定义为:
d=$(date +"%Y:%m:%d")
我尝试下一个:
sed -i 's/old-word/$d/g' *.txt
但它放了“$d”而不是正确的日期。
尝试这个:
sed -i 's/old-word/'$(date +"%Y:%m:%d")'/g' *.txt
单引号不展开变量值,使用双引号:
sed -i "s/old-word/$d/g" *.txt
在这里查看手册。