Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

macos - What is wrong with my string substitution using sed on Mac OS X?

I want to replace #Banner none with Banner /etc/sshd_banner that is within /etc/sshd_config. If I run

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

I get the following error

sed: 1: "/etc/sshd_config": unterminated substitute pattern

Any ideas on how to fix this issue?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Three problems with your command:

  1. You're missing the terminating /.
  2. You can't use / as delimiter anyway, because this character occurs in the string you're trying to replace/substitute. You should use a different character, such as a pipe character, as delimiter.
  3. In the version (BSD) of sed that ships with Mac OS X, the -i flag expects a mandatory <extension> argument, which your command is missing. An empty string ("") should follow the -i flag if you want to edit the file in-place with this version of sed.

In summary, try

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...