I'm writing server automation script using Chef, and I need to check the installed version of the PEAR package manager. The command line switch -V
prints the detailed version information to the console:
PEAR Version: 1.9.0
PHP Version: 5.3.5-1ubuntu7.2ppa1~lucid
Zend Engine Version: 2.3.0
Running on: Linux ubuntu-lucid-32-generic 2.6.32-33-generic #72-Ubuntu SMP Fri Jul 29 21:08:37 UTC 2011 i686
However, I'm unable to isolate the 1.9.0
part of that result and test against it. The pear script doesn't seem to be printing to STDOUT, since redirection isn't working either:
$ pear -V > pear_version
PEAR Version 1.9.0
...
$ cat pear_version
$
How can I capture the output and pass it to grep so I can return just "1.9.0"?
(Assuming your shell is a linux/unix variant like bash)
I don't have pear to test with but I would guess that the missing version info is going to STDERR, so try
pearVer=$(pear -V 2>&1 | sed '/^PEAR Version: /s///')
This only matches lines that begin with 'PEAR Version'. the 's///' is short hand for, 'match the first expression and replace it with '//' (nothing).
I hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With