Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Bash如何将stderr捕获到变量?
我想在我的 bash 脚本中做这样的事情
sh -c path/myExcecutable-bin 2>&1 =MYVARIABLE
如何将 stderror 输出发送到变量?
保存stdout 和 stderr到一个变量:
stdout
stderr
MYVARIABLE="$(path/myExcecutable-bin 2>&1)"
请注意,这会将 stdout 和 stderr 交错到同一个变量中。
仅 保存stderr到变量:
MYVARIABLE="$(path/myExcecutable-bin 2>&1 > /dev/null)"