I have a script that get python version from clients. The command in bash is:

pythonVer=$(ssh $user@$ip "python --version")

But this command shows the python version on stdout (my terminal that connect to clients) but I cannot assign this value to a variable. Just one server allow this, so when I tried write this var to a file, I can see only one version in this file, other version numbers are in only my terminal.

What is this issue about "python" command? How can I assign client's pyhton version to my var named pythonVer?


It seems python outputs its version to stderr, not stdout. So, redirect stderr to stdout in order to capture it

pythonVer=$(ssh "$user"@"$ip" 'python --version 2>&1')


pythonVer=$(ssh "$user"@"$ip" 'python --version' 2>&1)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.