How to redirect stderr and stdout to different files in the same line in script?

后端 未结 5 1668
既然无缘
既然无缘 2020-11-30 17:51

I know this much:

$ command 2>> error

$ command 1>> output

Is there any way I can output the stderr to the error file and outp

5条回答
  •  感动是毒
    2020-11-30 18:42

    Multiple commands' output can be redirected. This works for either the command line or most usefully in a bash script. The -s directs the password prompt to the screen.

    Hereblock cmds stdout/stderr are sent to seperate files and nothing to display.

    sudo -s -u username <<'EOF' 2>err 1>out
    ls; pwd;
    EOF
    

    Hereblock cmds stdout/stderr are sent to a single file and display.

    sudo -s -u username <<'EOF' 2>&1 | tee out
    ls; pwd;
    EOF
    

    Hereblock cmds stdout/stderr are sent to separate files and stdout to display.

    sudo -s -u username <<'EOF' 2>err | tee out
    ls; pwd;
    EOF
    

    Depending on who you are(whoami) and username a password may or may not be required.

提交回复
热议问题