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

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

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.

From OS X manual

-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.

zero-length = ""

Tags:

Macos

Sed