一條很簡單的替換文本的命令:
sed -i 's/www.a.cn/www.b.com/g' common.js,報錯command c expects \ followed by text
但是同樣的命令在服務器上是可以正確執行的,看了mac下的man sed,里面-i選項中的解釋:
Edit files in-place, saving backups with the specified extension.
If a zero-length extension is given, no backup will be saved. It
is not recommended to give a zero-length extension when in-place
editing files, as you risk corruption or partial content in situ-
ations where disk space is exhausted, etc.
大概的意思就是說用-i的選項時mac會進行強制備份,所以你必須給出一個后綴名進行備份,如果你不想進行備份,直接用空字符即可
sed -i '' 's/www.a.cn/www.b.com/g' common.js
