Home > Enterprise >  sed: -e expression #1, char 7: unterminated `s' command when running in bash script
sed: -e expression #1, char 7: unterminated `s' command when running in bash script

Time:01-11

New to bash scripting and I am trying to automate some standard server setup commands.

When I run the following sed command which I use all the time

sed 's/#Port 22/Port 55/' /etc/ssh/sshd_config

The command executes no problem, however when I place it into a bash script I get

ssh -p [email protected] sed 's/#Port 22/Port 55/' /etc/ssh/sshd_config

it fails with: sed: -e expression #1, char 7: unterminated s' command`

Note: IP and Port are bogus info for the sake of the post. Any and all help are greatly appreciated.

CodePudding user response:

This is because of quoting. Try:

ssh -p [email protected] "sed 's/#Port 22/Port 55/' /etc/ssh/sshd_config"

Without the quotes, you are effectively trying to run sed s/#Port 22/Port 55/ /etc/ssh/sshd_config which attempts to invoke the sed script s/#Port on the files 22/Port, 55/, and /etc/ssh/sshd_config.

  •  Tags:  
  • Related