shell脚本使用技巧2

0--stdin标准输入

1--stdout标准输出

2--stderr标准错误

 

重定向

echo "this is a good idea " > temp.txt

temp.txt内容会被首先清空后再输入“this is a good idea”

 

追加

echo "this is a bad idea " >> temp.txt

cat temp.txt

 

打印退出状态:echo $?

ls + 2>out.txt

2输入错误时候,输出到out.txt

cmd 2>stderr.txt 1>stdout.txt

正确输出到stdout.txt,错误输出到stderr.txt中;

重定向到同一个文件:

cmd 2>&1 output.txt

 

tee

打印stdout,并重向到一个文件中:tee

command | tee file1

cat a* | tee -a out.txt | cat -n

-a 会覆盖文件,-n给文件加数字号

将脚本内部的文本块进行重定向

#!/bin/bash

cat<<EOF>log.txt

LOG FILE HEADER

this is a test log file

Function:system staticstics

EOF

 

转载于:https://www.cnblogs.com/hujianglang/p/6965375.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值