0

Need to check the version of python so for that i am hitting this command in a script. I am trying to store the output of the given command in a variable "x".So that I can use this x in further script. But when I am trying to print x it is showing null value(no value).

[bin]$x=`/path/thirdparty/python/2.7/bin/python2.7 -V`
Python 2.7.8
[bin]$echo x

Please help me to store the value of the command in a variable.

kshitij
  • 13
  • 2

2 Answers2

1

python -V writes to the standard error, not to the standard output. So you have to redirect STDERR (2) to STDOUT (1).

$ x=$({python -V} 2>&1)
$ echo $x
Python 2.7.6
0

Hm... the output is possibly written to stderr, not stdout. Try this:

x=`/path/thirdparty/python/2.7/bin/python2.7 -V 2>&1` 
Axel
  • 13,939
  • 5
  • 50
  • 79