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?

3
  • 1
    Take a look at: Insert line after first match using sed Commented Jan 9, 2020 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? Commented Jan 10, 2020 at 4:01
  • I need it to be expanded and put the result in the file. Thats what i actually have, would really appreciate help: pastebin.com/pHfKTVnu Commented Jan 10, 2020 at 14:46

1 Answer 1

1
awk '{print} $0=="old line"{print "new line"}' file
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.