I’m writing a shell script that do some work after checking the version of python on the system.
and I do a=`python -V` and a echo of $a:
[root@machine folder]# a=`python -V`
Python 2.3.4
[root@machine folder]# echo $a
and echo $a just output nothing
at the same time I do:
[root@machine folder]# if grep "2.3.4" `python -V` ; then echo "bad" ; fi
Python 2.3.4
after I hit enter it just output the version of the python but nothing else.
Why it behaves like this? Is there other ways for me to do the same task?
python -Vappears to output onstderr. If you runthe output appears on the console (i.e. it’s not being picked up by the subshell assignment). However, if you redirect
stderrto stdout, thenworks