0

I have this Bash script but it is returning an error with the sed command(sed: -e expression #1, char 102: unknown option to `s').

Does anyone know how to fix this?

vhostConfig=$(cat "/etc/apache2/sites-available/$serverName.conf")
vhostConfig=$(echo "$vhostConfig" | sed "s/<VirtualHost \*:80>/<VirtualHost *:80>\nRewriteEngine On\nRewriteCond %{HTTPS} !=on\nRewriteRule ^/?(.*) https:\/\/$serverName\/ [R,L]/")

I tried to change the double quotes to single quotes but it did not work.

tripleee
  • 175,061
  • 34
  • 275
  • 318
Salocin
  • 9
  • 2

1 Answers1

1

You have the slash as the separator and the slashes in https:// which sed thinks they are the separators.

Just use different char as separator, eg ~.

sed "s~<VirtualHost *:80>~<VirtualHost :80>\nRewriteEngine On\nRewriteCond %{HTTPS} !=on\nRewriteRule ^/?(.) https://$serverName/ [R,L]~"
Adam
  • 639
  • 9
  • 22