0

Since I am new in Bash language, I was trying to make a simple script to find the apache2 PHP Config File (php.ini) in Ubuntu and echo a new line into it.

I have used the this code to find the currently used php.ini :

#!/bin/sh

php -i | grep "Loaded Configuration File"       && \
echo "zend_extension=/path/extension.so" > PHP.INI_GREPPED       && \
// The rest of my Code

So, Instead of the (PHP.INI_GREPPED) I want to use the found php.ini file in the previous command.

The output of (php -i | grep "Loaded Configuration File) Shows this:

Loaded Configuration File => /etc/php/7.4/cli/php.ini

I want to only take (/etc/php/7.4/cli/php.ini) to echo a new line into it.

Also, IS it possible to change the file path before echo into it? for example, the output of the grep command was:

 Loaded Configuration File => /etc/php/7.4/cli/php.ini

and I want to change the echo into :

/etc/php/7.4/apache2/php.ini

NOTE: 7.4 may change depending on the installed version of PHP.

Anyway to do that? sorry I am new to bash.

B Happy
  • 27
  • 2
  • 11

1 Answers1

1

Use sed:

php -i | grep Loaded\ Configuration\ File | sed 's/.*=> //'

And without grep:

php -i | sed -n '/^Loaded Configuration File/s/.*=> //p'
ceving
  • 21,900
  • 13
  • 104
  • 178