How to store standard error in a variable

后端 未结 18 2310
难免孤独
难免孤独 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:32

    A simple solution

    { ERROR=$(./useless.sh 2>&1 1>&$out); } {out}>&1
    echo "-"
    echo $ERROR
    

    Will produce:

    This Is Output
    -
    This Is Error
    

提交回复
热议问题