PHP Version mit Bash herausfinden

2012-06-19 00:00:00 IN1 , 2023-04-10 14:16:28 IN1


Langform

$ php -v | grep PHP -m 1 | awk '{print $2}'

⤷ Beispiel Ergebnis: 7.0.4-6+deb.sury.org~trusty+1

Kurzform

$ sLong=`php -v | grep PHP -m 1 | awk '{print $2}'`; echo ${sLong:0:3}

⤷ Beispiel Ergebnis: 7.0

Möchte man einen Wert ohne Punkt haben, bspw. weil ein solcher in einer weiteren Bash Verarbeitung einfacher vergleichbar ist, kann man noch einen sed Ausdruck hinzufügen, welcher Punkte entfernt.

$ long=`php -v | grep PHP -m 1 | awk '{print $2}'`;echo ${long:0:3} | sed 's/\.//g'

⤷ Beispiel Ergebnis: 70

This website uses Cookies to provide you with the best possible service. Please see our Privacy Policy for more information. Click the check box below to accept cookies. Then confirm with a click on "Save".