且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我在 Mac OS X 上使用 sed 替换字符串有什么问题?

更新时间:2022-12-05 14:53:50

使用另一个分隔符

Use another delimiter

这里我确实使用 " 作为分隔符

Eks here I do use " as delimiter

sudo sed -i "" "s|#Banner none|Banner /etc/sshd_banner|" /etc/sshd_config

通过改变分隔符,你不需要转义/

By changing the delimiter, you do not need to escape the /

你原来的帖子最后漏了一个/.

Your original post missed one / at the end.

来自 OS X 手册

-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 partial content in situations where disk
         space is exhausted, etc.

零长度 = "