$(($one/$zero)) 2> tasty.txt >> cat.txt
$(($one/$zero)) 2> tasty.txt >> cat.txt
我的输入
one=1
zero=0
为什么错误没有被重定向到tasty.txt,而是被打印出来?
因为当您在$()中执行命令时,它将打开一个新的子shell。
:-:echo "one is $one and Zero is $zero"
one is 1 and Zero is 0
:-:eval $one/$zero 2> error.txt
:-:cat error.txt
bash: 1/0: No such file or directory
当我在当前Shell中执行命令时,错误将重定向到文件。
:-:$($one/$zero) 2> error_1.txt
bash: 1/0: No such file or directory
:-:cat error_1.txt
当我在subshell中执行命令时,错误将重定向到标准输出。
:-:$($one/$zero 2> error_1.txt)
:-:cat error_1.txt
bash: 1/0: No such file or directory
:-:
但是当我在子shell内的文件中重定向标准错误时,它将被捕获。