Pipe only STDERR through a filter

后端 未结 7 987
夕颜
夕颜 2020-11-28 20:53

Is there any way, in bash, to pipe STDERR through a filter before unifying it with STDOUT? That is, I want

STDOUT ────────────────┐
                       ├         


        
相关标签:
7条回答
  • 2020-11-28 21:30

    The last part of this page of the Advanced Bash Scripting Guide is "redirecting only stderr to a pipe".

    # Redirecting only stderr to a pipe.

    exec 3>&1                              # Save current "value" of stdout.
    ls -l 2>&1 >&3 3>&- | grep bad 3>&-    # Close fd 3 for 'grep' (but not 'ls').
    #              ^^^^   ^^^^
    exec 3>&-                              # Now close it for the remainder of the script.
    

    # Thanks, S.C.

    This may be what you want. If not, some other part of the ABSG should be able to help you, it is excellent.

    0 讨论(0)
提交回复
热议问题