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的更多相关文章

  1. shell脚本常用技巧

    shell脚本常用技巧 1.获取随机字符串或数字 ~]#echo $RANDOM | md5sum | cut -c 1-6 ~]#openssl rand -base64 4 | cut -c 1- ...

  2. shell脚本使用技巧3--调试

    1.使用-x,开启shell脚本的跟踪调试功能 ex:bash -x script.sh or sh -x script.sh 2.使用set -x 和 set +x对脚本进行部分调试(输入中间的内容 ...

  3. shell脚本调试技巧

    shell脚本调试之工具——bashdb http://www.cnblogs.com/itcomputer/p/5011845.html

  4. shell脚本常规技巧

    邮件相关 发送邮件: #!/usr/bin/python import sys; import smtplib; from email.MIMEText import MIMEText mail_ho ...

  5. SHELL 脚本小技巧

    脚本很简单,直接上功能介绍及脚本,可以做模板使用: 记录日志,记录脚本开始执行时间.结束时间 usage 函数,脚本需接参数执行,避免误执行,告诉用户,这个脚本的使用方法 加锁,创建锁文件,脚本不允许 ...

  6. shell脚本小技巧

    输入参数错误时,退格会出现^H,这个时候只要在脚本顶部加一条语句:stty erase ^h就可以了 #!/bin/sh stty erase ^h

  7. shell脚本使用技巧5--字符分隔

    #!/bin/bash #filename:ifs.sh data="name,sex,rollon,location" oldIFS=$IFS IFS=, for item in ...

  8. shell脚本使用技巧4--读取字符,重复执行

    ls | cat -n > out.txt 给输出的信息加行号并导出到out.txt 利用shell生成一个独立的进程 pwd; (cd /bin; ls); pwd; 开启一个子shell,不 ...

  9. Shell脚本小技巧收集

    1.使用python快速搭建一个web服务器 访问端口8000 python -m SimpleHTTPServer 2.获取文件大小 stat -c %s $file stat --printf=' ...

随机推荐

  1. 在java中获取URL的域名或IP与端口

    package com.xxl.sso.sample; import java.net.URI; import java.net.URISyntaxException; public class te ...

  2. git tag用法

    git tag //查看tag git tag test_tag c809ddbf83939a89659e51dc2a5fe183af384233 //在某个commit 上打tag git tag. ...

  3. python--使用递归的方式建立二叉树

    树和图的数据结构,就很有意思啦. # coding = utf-8 class BinaryTree: def __init__(self, root_obj): self.key = root_ob ...

  4. 使用python解决算法和数据结构--使用栈实现进制转换

    可以将10进制数据转换成2进制,8进制,16进制等. 晚上练练算法和数据结构哈. # coding = utf-8 class Stack: def __init__(self): self.item ...

  5. h5网页在微信里打开 右上角分享到微信好友或者朋友圈

    首先你需要一个分享接口地址,然后在自定义图片 标题 描述 如下: <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js& ...

  6. A - Points and Segments CodeForces - 429E

    题解: 方法非常巧妙的一道题 首先考虑要求全部为0怎么做 发现是个欧拉回路的问题(很巧妙) 直接dfs一遍就可以了 而这道题 要求是-1,1,0 我们可以先离散化 完了之后判断每个点被奇数还是偶数条边 ...

  7. MySQL事务提交过程(二)

    上一篇文章我们介绍了在关闭binlog的情况下,事务提交的大概流程.之所以关闭binlog,是因为开启binlog后事务提交流程会变成两阶段提交,这里的两阶段提交并不涉及分布式事务,当然mysql把它 ...

  8. ArcGIS 10开发迁移策略(待续)

    1.更改 ESRI.ArcGIS.ADF 程序集 ArcGIS 10 中, ADF 程序集中的功能被分散到不同的程序集中,如果将 ArcGIS 9.3 下 开发的自定义组件迁移到 ArcGIS 10 ...

  9. zTree实战

    1.实体 public class UserDataZTreeVo { private String id; private String pid; private String name; priv ...

  10. 010 异步处理Rest服务

    一:任务 1.任务 使用Runnable异步处理Rest服务 使用DefaultResult异步处理Rest服务 异步处理的配置 2.原理图说明 二:Callable进行异步处理 1.程序 新建一个a ...