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.

0

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

Comments

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` 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.