How to store standard error in a variable

后端 未结 18 2115
难免孤独
难免孤独 2020-11-22 12:46

Let\'s say I have a script like the following:

useless.sh

echo \"This Is Error\" 1>&2
echo \"This Is Output\" 

And I have an

18条回答
  •  长情又很酷
    2020-11-22 13:27

    # command receives its input from stdin.
    # command sends its output to stdout.
    exec 3>&1
    stderr="$(command &1 1>&3)"
    exitcode="${?}"
    echo "STDERR: $stderr"
    exit ${exitcode}
    

提交回复
热议问题