如何追加的&QUOT输出;蟒蛇--version"在bash shell中的文件? [英] How to append output of "python --version" to a file in bash shell?
问题描述
我试图写一个简短的脚本登录我当前的shell会话文件的特定环境变量。不幸的是蟒蛇--version输出似乎忽略(?)>>操作符,并打印到外壳,而不是到文件。
我最小的(不)工作的例子:
RM path.log
回声蟒蛇--version>> path.log
蟒蛇--version>> path.log
我希望该文件path.log随后将有以下内容:
蟒蛇--version
Python的2.6.6
但是行的Python 2.6.6被打印到外壳,而不是到该文件。我该如何解决这个问题?
感谢您!
PS:这工作完全罚款
的gcc --version
蟒蛇--version
输出 STDERR
您需要合并 STDERR
到 STDOUT
:
蟒蛇--version>> path.log 2 - ;&放大器; 1
有关引用,可以说验证这种行为:
$蟒蛇--version 1>的/ dev / null的
Python的2.7.4
的 STDOUT
在上面的例子中被重定向到的/ dev / null的
。这意味着,输出被发送到 STDERR
。
I'm trying to write a short script to log certain environment variables of my current shell session to file. Unfortunately the output of "python --version" seems to ignore (?) the >> operator and prints to the shell instead to the file.
My minimal (not) working example:
rm path.log
echo "python --version" >> path.log
python --version >> path.log
I would expect that the file path.log would then have the following content:
python --version
Python 2.6.6
But the line "Python 2.6.6" is printed to the shell and not to the file. How can I fix this?
Thank you!
PS: This works completely fine for
gcc --version
python --version
outputs to STDERR
.
You need to merge STDERR
into STDOUT
:
python --version >> path.log 2>&1
For reference, you can verify such behavior by saying:
$ python --version 1>/dev/null
Python 2.7.4
The STDOUT
in the above example was redirected to /dev/null
. This would imply that the output is being sent to STDERR
.
这篇关于如何追加的&QUOT输出;蟒蛇--version"在bash shell中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!