9

I am currently installing php7.0 and was wondering if there is an shorter way to install the modules. normally I type:

    apt-get install php7.0 php7.0-fpm php7.0-mbstring php7.0-mcrypt 
     php7.0-phpdbg php7.0-dev php7.0-curl php7.0-sqlite3 php7.0-json 
     php7.0-gd php7.0-cli

Is there an regular expression so you don't have to type php7.0 over and over again? Something like:

   apt-get install php7.0-{fpm mbstring mcrypt phpdbg dev curl sqlite3 
    json gd cli}

I searched for something like this for hours but could not find it. In advance thanks for your reply.

  • 1
    What about apt-get install php7*? Short enough? But it will simply install all possible php7 packages. – Videonauth Jun 12 '16 at 13:02
  • @Videonauth worse - it will install all packages containing php anywhere in the package name. – muru Jun 13 '16 at 19:48

1 Answers1

15

As @Videonauth suggested, you can use apt-get install php7.* but that will install all packages whose names contain php7. To install those whose names starts with php7, use apt-get install '^php7. *. To instal only those on your list, you can use brace expansion. The format is almost what you already tried: braces but a comma-separated list:

$ echo foo{a,b,c}
fooa foob fooc

Therefore:

$ echo php7.0-{fpm,mbstring,mcrypt,phpdbg,dev,curl,sqlite3,json,gd,cli}
php7.0-fpm php7.0-mbstring php7.0-mcrypt php7.0-phpdbg php7.0-dev php7.0-curl php7.0-sqlite3 php7.0-json php7.0-gd php7.0-cli

So, you could run:

sudo apt-get install php7.0-{fpm,mbstring,mcrypt,phpdbg,dev,curl,sqlite3,json,gd,cli}
terdon
  • 100,812
  • He he, wasn't sure about if those brace expansions will work, so I only commented. – Videonauth Jun 12 '16 at 13:09
  • @Videonauth yup, they do, they just need space. You can also do things like echo {1..10} or echo {01..10}. Useful stuff. – terdon Jun 12 '16 at 13:09
  • No, php7* does not install packages starting with php7. apt-get uses regular expressions, not wildcards. Unless you have files named php7-foo in your current directory, php7* will be passed by the shell to apt-get, which will treat it as a regex and match it over the entire package name. So every package containing php in its name will be selected for installation. People have been bit by this, repeatedly: http://askubuntu.com/questions/210976/apt-get-remove-with-wildcard-removed-way-more-than-expected-why – muru Jun 15 '16 at 00:38
  • @muru eek! Thanks, I'd forgotten the .. – terdon Jun 15 '16 at 07:40
  • @terdon not just the ., you'll need to anchor the expression with ^ – muru Jun 15 '16 at 07:41
  • @muru true. I was thinking that php7 was specific enough but you're right, there may be unwanted packages containing the string. – terdon Jun 15 '16 at 07:45