Mac下用sed报错 command c expects followed by text

一条很简单的替换文本的命令:

1 sed -i 's/www.a.cn/www.b.com/g' common.sh

执行时报错command c expects \ followed by text
也有可能报错 invalid command code W

但是同样的命令在服务器上是可以正确执行的,看了mac下的man sed,里面-i选项中的解释:

     -i extension
             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 par-
             tial content in situations where disk space is exhausted, etc.

 

大概的意思就是说用-i的选项时mac会进行强制备份,所以你必须给出一个后缀名进行备份,如果你不想进行备份,直接用空字符即可

1 sed -i 's/www.a.cn/www.b.com/g' common.sh

 

posted @ 2019-07-16 19:25  orzs  阅读(1225)  评论(0编辑  收藏  举报