我有一个程序可以将信息写入stdout和stderr,并且我需要grep通过什么来到stderr,而忽略了stdout.
我当然可以分2步完成:
command > /dev/null 2> temp.file
grep 'something' temp.file
Run Code Online (Sandbox Code Playgroud)
但我宁愿能够在没有临时文件的情况下做到这一点.有没有任何智能管道技巧?
我想将进程的stdout和stderr重定向到单个文件.我怎么用Bash做到这一点?
是否可以在不使用临时文件的情况下在不同的变量中存储或捕获stdout和stderr ?现在我这样做是为了out在err运行时获取stdout 和stderr some_command,但是我想避开临时文件.
error_file=$(mktemp)
out=$(some_command 2>$error_file)
err=$(< error_file)
rm $error_file
Run Code Online (Sandbox Code Playgroud)