码迷,mamicode.com
首页 > 系统相关 > 详细

shell脚本使用技巧2

时间:2017-06-09 00:49:04      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:stderr   字号   bin   cmd   cst   标准输入   com   $?   eof   

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

 

shell脚本使用技巧2

标签:stderr   字号   bin   cmd   cst   标准输入   com   $?   eof   

原文地址:http://www.cnblogs.com/hujianglang/p/6965375.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!