linux文件重定向

1:标准输出;2:错误输出

1,exec启动一个新的shell将STDOUT文件描述符重定向到文件

#!/bin/sh
echo "test exec..."
exec > out.txt
exec 2> out.error
echo "this is the first line"

#故意生成错误信息,将输出重定向都stderr文件描述符

echo "this is the second line" > &2

2,如果将错误和标准输出都重定向到同一个文件,可以使用:

ls -al test test1 badtest &> out.txt

原文地址:https://www.cnblogs.com/bobodeboke/p/3756736.html