Shell输出重定向

By admin, 11 五月, 2021

To redirect stderr to stdout and have error messages sent to the same file as standard output, use the following:

正确的写法:command > file 2>&1

> file redirect the stdout to file, and 2>&1 redirect the stderr to the current location of stdout.

The order of redirection is important. For example, the following example redirects only stdout to file. This happens because the stderr is redirected to stdout before the stdout was redirected to file.

错误的写法:command 2>&1 > file

Another way to redirect stderr to stdout is to use the &> construct. In Bash &> has the same meaning as 2>&1:

参考:https://linuxize.com/post/bash-redirect-stderr-stdout/

评论

Restricted HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img src>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。
验证码
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
请输入"Drupal10"