linux呈现数据

标准的文件描述符

文件描述符        缩写        描述
    0           STDIN       标准输入
    1           STDOUT      标准输出
    2           STDEER      标准错误   

STDOUT文件的标准输出 在终端页面上,标准输出是终端显示器

输出重定向

[zhidaobu@localhost test]$ ls -l > 1.txt
[zhidaobu@localhost test]$ cat 1.txt
总用量 4
-rw-rw-r--. 1 zhidaobu zhidaobu  0 10月 29 21:37 1.txt
-rw-rw-r--. 1 zhidaobu zhidaobu 75 10月  9 19:21 2.txt
-rw-rw-r--. 1 zhidaobu zhidaobu  0 9月  26 11:22 text3
[zhidaobu@localhost test]$ 

STDEER

重定向错误

2>

[zhidaobu@localhost test]$ ls -al fwfwf 2> 1.txt
[zhidaobu@localhost test]$ cat 1.txt
ls: 无法访问'fwfwf': 没有那个文件或目录

1>正常输出重定向数据

全部重定向,将STDERR STDOUT的输出重定向到一个文件中

&>

在脚本中重定向输出

临时重定向

[zhidaobu@localhost test]$ ls
1.txt  2.txt  text3
[zhidaobu@localhost test]$ vim 1.txt
[zhidaobu@localhost test]$ bash 1.txt
this is a error
this is a normal output
[zhidaobu@localhost test]$ bash 1.txt 2>2.txt
this is a normal output
[zhidaobu@localhost test]$ cat 1.txt
#!/bin/bash
echo "this is a error" >&2
echo "this is a normal output"

[zhidaobu@localhost test]$ cat 2.txt
this is a error
[zhidaobu@localhost test]$ 

永久重定向

如果使用大量的数据需要重定向,那重定向每个echo语句就会很繁琐

可以使用exec命令告诉shell在脚本执行期间重定向某个特定文件描述符

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值