0

For my actual creating intial server setup script i need to add a line thats saved in a variable after a specific line in a specific file.

I want to add the line:

zend_extension = $phpextensiondir/ioncube_loader_lin_$phpextensionnumber.so

after the following line:

;realpath_cache_ttl = 120

in the following files:

  • /etc/php/$phpversionnumber/cli/php.ini
  • /etc/php/$phpversionnumber/cli/fpm.ini

I was looking around, but can't find any what I understand. Actually I'm new to bash scripting. Can anybody explain? It seems that sed is not the right choice for it?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
yFStein
  • 29
  • 7
  • 1
    Take a look at: [Insert line after first match using sed](https://stackoverflow.com/questions/15559359/insert-line-after-first-match-using-sed) – Paul Lemmons Jan 09 '20 at 15:57
  • Hmm, tricky. Do you want to put the literal strings '$phpextensiondir' and '$phpextensionnumber' in the file, or do you want them to be expanded and put the result in the file? Eg, should the file contain the dollar signs and the variable names phpextensiondir and phpextensionnumber or should those things be expanded and then inserted, eg, if $phpextensiondir was "c:\php_new\ext" and $phpextensionnumber was 5 then the file would end up containing zend_extension = c:\php_new\ext/ioncube_loader_lin_5.so. I assume there is an env variable for phpversionnumber, such as phpversionumber=7.4? – Brenda J. Butler Jan 10 '20 at 04:01
  • I need it to be expanded and put the result in the file. Thats what i actually have, would really appreciate help: https://pastebin.com/pHfKTVnu – yFStein Jan 10 '20 at 14:46

1 Answers1

1
awk '{print} $0=="old line"{print "new line"}' file
Ed Morton
  • 188,023
  • 17
  • 78
  • 185