I am running Debian 8 Jessie, trying to install PHP command line intepreter from a shell script.
Here is what I do:
sudo apt-get install php-cli
it tells me there is no php-cli
. I do find there is php5-cli
. However, to make my script more robust, e.g. when running on a recent ubuntu server offering php7
, I do not want to specify php5-cli
.
I googled for an answer but what I get only confused me:
xrfang@P-qapub:~$ sudo apt-get install --names-only "php*-cli"
E: Command line option --names-only is not understood
xrfang@P-qapub:~$ sudo apt-cache search --names-only php-cli
php-google-api-php-client - Google APIs client library for PHP
xrfang@P-qapub:~$ apt-cache search --names-only "php\d+-cli$"
xrfang@P-qapub:~$ apt-cache search --names-only "php\d-cli$"
xrfang@P-qapub:~$ apt-cache search --names-only "php\\d-cli$"
xrfang@P-qapub:~$ apt-cache search --names-only "php5-cli$"
php5-cli - command-line interpreter for the php5 scripting language
My questions are:
I do not want the Google API for PHP, so I try to use regex, but as shown above it just does not accept
\d
.Is it possible to use --name-only somehow with
apt-get install
, notapt-cache search
.
Thanks!
Is it possible to use --name-only somehow with
apt-get install
, notapt-cache search
.By default
apt-cache search
searches informations from the available package names and their long description.--names-only
restricts this search only to the package names.Now
apt-get
doesn't care about description. It will try a package name verbatim, and if not found, will consider the parameter as a regex (while not really documented, actually an extended regular expression). This regex will be used only to match package name(s) from the list of known packages. So there's no--names-only
option available: considerapt-get
is under permanent effect of this option.I do not want the Google API for PHP, so I try to use regex, but as shown above it just does not accept
\d
.apt-get
accepts (extended) regular expressions, not Perl Compatible Regular Expression.\d
means a digit only in a PCRE and has no special meaning in BRE or ERE. A digit in a regular expression can be represended by[0-9]
(or for fun[[:digit:]]
as an extended regular expression syntax).Your search would be:
To install any php cli numbered version, that would be:
[...]
This will install
php5-cli
and its dependencies.Please note the usage of
^
and$
to delimit start and end of the package name selected: once the expression is used as a regex, it can be any part of a package's name, so better be careful. Eg tryingapt-get install .
will attempt to install any package having at least one character: all of them, and will of course fail for conflicts.For the small details:
php4-cli
doesn't exist in Jessie, but is referenced by an other package (php-xajax
) that's why it's selected as candidate since it matched the regex. Of course it's not installable so won't be listed in the end.