Checking PEAR Version

I am writing a script server automation using Chef and I need to check the installed version of the PEAR package manager. The -V command line switch prints 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 can not isolate 1.9.0 part of this result and test it. The pear script does not seem to print in STDOUT, since the redirect also does not work:

 $ pear -V > pear_version PEAR Version 1.9.0 ... $ cat pear_version $ 

How can I capture the output and pass it grep so that I can only return "1.9.0"?

+4
source share
1 answer

(Assume your shell is a linux / unix variant like bash)

I donโ€™t have a pear for testing, but I would suggest that the missing version information goes to STDERR, so try

  pearVer=$(pear -V 2>&1 | sed '/^PEAR Version: /s///') 

This only matches lines starting with "PEAR Version". 's ///' is a short combination, 'match the first expression and replace it with' // '(nothing).

Hope this helps.

+2
source

Source: https://habr.com/ru/post/1385979/


All Articles