Redirect stderr and stdout in Bash

后端 未结 15 1044
日久生厌
日久生厌 2020-11-22 08:18

I want to redirect both stdout and stderr of a process to a single file. How do I do that in Bash?

15条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 08:49

    For situation, when "piping" is necessary you can use :

    |&

    For example:

    echo -ne "15\n100\n"|sort -c |& tee >sort_result.txt
    

    or

    TIMEFORMAT=%R;for i in `seq 1 20` ; do time kubectl get pods |grep node >>js.log  ; done |& sort -h
    

    This bash-based solutions can pipe STDOUT and STDERR separately (from STDERR of "sort -c" or from STDERR to "sort -h").

提交回复
热议问题