重定向错误和数据 ls -al test test2 test3 badtest 2> test6 1> test7 #错误输入到test6,正常数据显示到test7
ls -al test test2 &> test8 #将标准错误和标准输入都重定向到test8
在脚本中重定向输出
将文本输出到标准错误中 echo "This is an error message" >&2
可以使用 exec 命令告诉shell脚本在执行期间重定向某个特定文件描述符
echo "This is the startof the script";
echo "now redirecting alloutputto another location";
exec 1> testout
exec 2> testerror
echo "This output should goto the testout file";
echo "This output should goto the testerror file" >&2;