linux 重定向

来源:互联网 发布:windows正在下载更新0 编辑:程序博客网 时间:2024/06/09 20:46

linux shell下常用输入输出操作符是:

  • 标准输入standard input 0
  • 正确输出standard output 1
  • 错误输出:error output 2
    默认是1。
    有如下test.sh
#!/bin/bashdatel3

执行脚本
./test.sh 1> suc.log 2>err.log 2>&2
运行结果:
suc.log

Tue May 17 12:31:14 CST 2016

err.log

./test.sh: line 3: l3: command not found

说明:
1>把标准输出输出到suc.log
2>把错误输出输出到err.log
2>&2的意思是:把错误输出输出到错误输出的文件(err.log),注意不能有2>>&2这种写法

一般把正确和错误都输出到同一个文件:

./test.sh &>> test.log

等价

./test.sh >> test.log 2>&1
1 0
原创粉丝点击