您的位置:首页 > 运维架构 > Linux

linux 重定向

2016-05-17 12:34 399 查看
linux shell下常用输入输出操作符是:

标准输入standard input 0

正确输出standard output 1

错误输出:error output 2

默认是1。

有如下test.sh

#!/bin/bash
date
l3


执行脚本

./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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: