I am new to bash and working on simple script..
I uses this command in my script:
php -i | sed -n '/^Loaded Configuration File/s/.*=> //p'
The output is like this:
/etc/php/7.4/cli/php.ini
I want to strip the version part and save it into a variable, without the dot.
I want to make a variable with only the php version, for example in the result above my variable should be:
version=$"74"
if php version 7.3, The version variable should be 73 .. and so on ..
Is there any way to do it?
2
Answers
If you’re concerned about the command-line version and you want to have the version of it, you can run PHP code by it (
-r
switch) and directly fetch the information:This spares you to pipe into sed (which is not a bad idea in general, but do as little as necessary and PHP knows about its version already).
With php:
Output: