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. 八卦一下Starlark语言

    八卦一下Starlark语言 编译移植TensorFlow时用到Bazel这一构建工具,Bazel用Starlark语法来编写WORKSPACE/BUILD文件,它们是类似于Make中的makeifl ...

  2. caffe关闭建立网络的log输出

    C++ google::InitGoogleLogging("XXX"); google::SetCommandLineOption("GLOG_minloglevel& ...

  3. SqlServer 四大排名函数(ROW_NUMBER、RANK、DENSE_RANK、NTILE)简介

    CREATE TABLE [dbo].[Order]( [ID] [int] IDENTITY(1,1) NOT NULL, [UserId] [int] NOT NULL, [TotalPrice] ...

  4. Oozie如何和安装部署

    1.Oozie的简单介绍: .Oozie是一个工作流引擎服务器,用于运行hadoop map/reduce和hive等任务工作流,同时Oozie还是一个Java web程序,运行在Java Servl ...

  5. windows server远程连接提示“终端服务器超出了最大允许连接”

  6. hdfs基本操作

    hdfs基本操作 1.查询命令 hadoop dfs -ls /   查询/目录下的所有文件和文件夹 hadoop dfs -ls -R 以递归的方式查询/目录下的所有文件 2.创建文件夹 hadoo ...

  7. ifconf家族命令

    1  ifconfig 命令: ifconfig 命令用来查看和配置网络设备.当网络环境发生改变时可通过此命令对网络进行相应的配置. 查看: ifconfig : 显示正在激活中的网卡 ifconfi ...

  8. Codeforces 342D Xenia and Dominoes 状压dp

    码就完事了. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define ...

  9. String.IsNullorEmpty()方法的使用

    != null 就是不为null !string.IsNullOrEmpty  不是null且不是""(string.Empty)

  10. mysql group_concat时间用法

    第一张表的worksId在第二张表中对应多条数据,需要将每条数据的日期作为结果查询出来,一个作为“初审时间”,另一个作为“复审时间”: 可以使用group_concat 和 group by 来进行分 ...