0

I'm trying to build my own bash script for installing LEMP (nginx mariadb php). I've managed to pull it off but I got stuck at the part where I need to add the 'index.php' text to the index line @ /etc/nginx/sites-avaliable/default.

I've tried with "sed" and got very close but not there yet.

sed '/\index.htm/i index.php' input /etc/nginx/sites-available/default

that was the closest I got

i also tried replacing the index.htm file like this :

sed 's/index.htm/index.php' /etc/nginx/sites-available/default

Thanks for the help! :)

Barmar
  • 741,623
  • 53
  • 500
  • 612
Gilush
  • 81
  • 8

1 Answers1

1

If you want to replace in the input file, you have to use the -i option. Otherwise sed sends the output to stdout.

The s command requires a terminating delimiter.

sed -i 's/index.html/index.html index.php/' /etc/nginx/sites-available/default
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Thank you! is there a way to append the index.php after the index.html instead of replacing it? – Gilush Feb 11 '20 at 01:49
  • by the way the sed -i just replaced the 'htm' with php and left the 'l' (of html) so that didn't work :( – Gilush Feb 11 '20 at 02:01
  • Change it to `index.html`. – Barmar Feb 11 '20 at 02:05
  • What is actually in the original file? I assumed you knew what you wanted to replace, and just needed to know the correct syntax. – Barmar Feb 11 '20 at 02:06
  • lol i can't. the index.html must be in this line and cannot be raplaced. i'm trying to add index.php after it or at least replace the index.htm file that comes after index.html – Gilush Feb 11 '20 at 02:07
  • the line should look like this: "index.html index.htm index.php;" – Gilush Feb 11 '20 at 02:08