96

I just installed PHP on Ubuntu Natty from source.

I'm trying to use PECL to install additional modules like APC and Memcache. I'm using something like this:

pecl install apc

However, I get prompts asking me to confirm things.

How can I use the pecl command to just accept the defaults? I saw something like this on a message board: printf "yes\n" | pecl install pecl_http. However, in the case of APC this would answer yes for things where the default is no (I think).

starball
  • 20,030
  • 7
  • 43
  • 238
ObiHill
  • 11,448
  • 20
  • 86
  • 135
  • 1
    @Gordon: I tried that but there doesn't seem to be a handle for what I need. – ObiHill Nov 15 '11 at 19:37
  • 1
    For the case where the default values are acceptable, in non interactive mode, PECL prompt is not required. For example, if you add to a Dockefile `RUN pecl install apc`, at build time, you'll get the default values automatically selected. – Dereckson Apr 21 '15 at 22:08

4 Answers4

97

The following code seems to work ok:

printf "\n" | pecl install apc

You can also replace apc with any other PECL package.

Cheers.

ObiHill
  • 11,448
  • 20
  • 86
  • 135
93

The "yes" command can do more than just type "yes"; it can type anything you want, over and over. Including an empty line, which is a good way to accept defaults.

I just needed this myself, so here is what worked well for me:

yes '' | pecl install -f apc
Nate
  • 18,752
  • 8
  • 48
  • 54
Tom Boutell
  • 7,281
  • 1
  • 26
  • 23
  • Thanks for the input, Tom. Was your code meant to be `"yes\n" | pecl install -f apc`?! – ObiHill Feb 12 '14 at 07:39
  • 4
    @ObinwanneHill: Tom was referring to the [`yes`](http://linux.die.net/man/1/yes) command. The benefit of this over `printf` is that it generates output repeatedly, which makes it more portable should the pecl installer prompt for additional questions than your scripted `printf` expected. – jmikola Apr 09 '14 at 06:53
  • @jmikola Oh I see, was not familiar with that command. Thanks – ObiHill Apr 09 '14 at 07:03
  • 1
    The problem comes when you want a NO instead of a YES in any of the options – ln -s Nov 09 '22 at 19:56
15

If you don't want give the same answer for every single prompt ("yes", "no", or ""), you can use --configureoptions to set specific values for each option (see the PECL manual).

You'll want to find your package's package.xml file to see what options are configurable. As an example, for the memcached package, you'd go here:

https://github.com/php-memcached-dev/php-memcached/blob/master/package.xml

Search for the <configureoption> tags, which in this case are:

<configureoption name="with-libmemcached-dir"     prompt="libmemcached directory"     default="no"/>
<configureoption name="with-zlib-dir"             prompt="zlib directory"             default="no"/>
<configureoption name="with-system-fastlz"        prompt="use system fastlz"          default="no"/>
<configureoption name="enable-memcached-igbinary" prompt="enable igbinary serializer" default="no"/>
<configureoption name="enable-memcached-msgpack"  prompt="enable msgpack serializer"  default="no"/>
<configureoption name="enable-memcached-json"     prompt="enable json serializer"     default="no"/>
<configureoption name="enable-memcached-protocol" prompt="enable server protocol"     default="no"/>
<configureoption name="enable-memcached-sasl"     prompt="enable sasl"                default="yes"/>
<configureoption name="enable-memcached-session"  prompt="enable sessions"            default="yes"/>

You can then pass these options along to the install command like so:

pecl install --configureoptions 'with-libmemcached-dir="no" with-zlib-dir="no" with-system-fastlz="no" enable-memcached-igbinary="yes" enable-memcached-msgpack="no" enable-memcached-json="no" enable-memcached-protocol="no" enable-memcached-sasl="yes" enable-memcached-session="yes"' memcached
Ben Y
  • 1,711
  • 1
  • 25
  • 37
9

Obinwanne's Hill answer nailed it for me, so I'm not providing anything new here, but the following seems like the absolute shortest also without any fancy tools.

echo '' | pecl install apc
Ian Bytchek
  • 8,804
  • 6
  • 46
  • 72