[英]Bash script to get php version
I would like to get the current numerical value for php in the php.ini path.我想在 php.ini 路径中获取 php 的当前数值。 I understand that php -v gets me a bunch of info, but I just need the "7.2" or whatever the current version is from the php.ini path.
我知道 php -v 为我提供了一堆信息,但我只需要“7.2”或来自 php.ini 路径的任何当前版本。
Edit: I'm building an automation script and if the version changes, I need to be able to know what was installed when I ran apt-get install php
编辑:我正在构建一个自动化脚本,如果版本发生变化,我需要能够知道运行
apt-get install php
时安装了什么
This script gets me the line i care about:这个脚本让我得到了我关心的那一行:
php --ini | grep Loaded | cut -d' ' -f12
The result (as of today) is结果(截至今天)是
/etc/php/7.2/cli/php.ini
Whats the best in bash way to echo "7.2"
assuming that the /etc/php
will not change (its unlikely based on the history of where php installs using apt-get)假设
/etc/php
不会改变,bash 最好的回应"7.2"
方式是什么(根据使用 apt-get 安装 php 的历史,这不太可能)
I'm open to other methods that don't involve php --ini, I just need the 7.2 (or whatever that path value may morph into).我对不涉及 php --ini 的其他方法持开放态度,我只需要 7.2(或该路径值可能会变成的任何内容)。
If you're building your automations with apt, then you should be relying on apt and/or dpkg to get the relevant information.如果您使用 apt 构建自动化,那么您应该依靠 apt 和/或 dpkg 来获取相关信息。
dpkg -l 'php*' | grep ^ii
For completenes, yum/dnf/rpm:对于完整的,yum/dnf/rpm:
rpm -qa 'php*'
我一问,就意识到我可以调整分隔符并查找第 4 项。
php --ini | grep Loaded | cut -d'/' -f4
This way uses CLI这种方式使用CLI
php -r "echo substr(phpversion(),0,3);"
OR或者
php -r "echo implode('.', array_slice(explode('.', PHP_VERSION),0,2));"
I would like to get the current numerical value for php in the php.ini path.我想在 php.ini 路径中获取 php 的当前数值。 I understand that php -v gets me a bunch of info, but I just need the "7.2" or whatever the current version is from the php.ini path.
我知道 php -v 为我提供了一堆信息,但我只需要“7.2”或来自 php.ini 路径的任何当前版本。
Edit: I'm building an automation script and if the version changes, I need to be able to know what was installed when I ran apt-get install php
编辑:我正在构建一个自动化脚本,如果版本发生变化,我需要能够知道运行
apt-get install php
时安装了什么
This script gets me the line i care about:这个脚本让我知道我关心的行:
php --ini | grep Loaded | cut -d' ' -f12
The result (as of today) is结果(截至今天)是
/etc/php/7.2/cli/php.ini
Whats the best in bash way to echo "7.2"
assuming that the /etc/php
will not change (its unlikely based on the history of where php installs using apt-get)假设
/etc/php
不会改变,bash 最好的回应"7.2"
方式是什么(根据使用 apt-get 安装 php 的历史,这不太可能)
I'm open to other methods that don't involve php --ini, I just need the 7.2 (or whatever that path value may morph into).我对不涉及 php --ini 的其他方法持开放态度,我只需要 7.2(或该路径值可能会变成的任何内容)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.