shell中的输入输出和编程中的变量(shell 03)
shell中的输入输出
标准输入:键盘
标准输出:终端显示器
>> 追加是换行追加的
echo 
-n 不尾随换行符  
-e 启用解释反斜杠的转义功能  
-E 禁用解释反斜杠的转义功能(默认)  
      --help 显示此帮助信息并退出  
      --version 显示版本信息并退出
只用cat
cat<filename1>filename2
内联输入重定向
command<<EOF(标识符)
data 
EOF (标识符)
在脚本中重定向输入输出
临时重定向
永久重定向
1.临时重定向
 command>&文件描述符
[root@localhost110 ~]# cat h.sh
#! /bin/bash
echo 'test error' >&2
echo 'normal output'
 [root@localhost110 ~]# chmod u+x h.sh
[root@localhost110 ~]# ./h.sh
test error
normal output
[root@localhost110 ~]# ./h.sh 2>errlog
normal output
[root@localhost110 ~]# cat errlog
test error
2、永久重定向
exec 文件描述符>文件名
[root@localhost110 ~]# cat h.sh
#! /bin/bash
exec 1>output
echo 'test error' >&2
echo 'output1'
echo "output2"
[root@localhost110 ~]# ./h.sh
test error
[root@localhost110 ~]# cat output
output1
output2
h.sh内容
[root@localhost110 ~]# ./h.sh
[root@localhost110 ~]# cat output
output1
output2
[root@localhost110 ~]# cat output_err
test error
test error2
输入重定向
exec 0<filename
h1.sh内容
[root@localhost110 ~]# chmod u+x h1.sh
[root@localhost110 ~]# ./h1.sh
line #1:test error
line #2:test error2
管道
将一个命令的输出重定向至另一个命令的输入
command1|command2
2命令是同时进行的不是先执行完一个再继续下一个的
tee 输出到文件
[root@localhost110 ~]# date
2016年 10月 16日 星期日 09:52:05 EDT
[root@localhost110 ~]# date|tee datefile
2016年 10月 16日 星期日 09:52:17 EDT
[root@localhost110 ~]# cat datefile
2016年 10月 16日 星期日 09:52:17 EDT
shell编程中的变量
用户自定义变量
系统环境变量
按照作用范围
脚本中的自定义变量
环境变量
  局部环境变量
  全局环境变量
shell脚本中的自定义变量规则
合法字符:字母,数字,下划线
合法字符数量:<=20
特别注意:区分大小写
变量声明
变量名=变量值  如var=1
变量值的类型:自动分配 数字,字符串 日期,数组
调用方式: $变量名 如$var
作用范围:脚本生存周期内
`可把命令执行后的结果赋给变量
[root@localhost110 ~]# date
2016年 10月 16日 星期日 :: EDT
[root@localhost110 ~]# mdate=`date`
[root@localhost110 ~]# echo $mdate
2016年 10月 16日 星期日 :: EDT
mdate=`date +%Y-%m-%d`
echo $mdate
--
shell中的输入输出和编程中的变量(shell 03)的更多相关文章
- netty中的channelPipeline在编程中的作用
		
在netty编程中我们绝大多数是要是用nio的,nio相比传统的io更加高效,而nio中核心概念离不开channel,buffer,selector三个重要的对象. 那么在netty中有一个chann ...
 - Python 3中套接字编程中遇到TypeError: 'str' does not support the buffer interface的解决办法
		
转自:http://blog.csdn.net/chuanchuan608/article/details/17915959 目前正在学习python,使用的工具为python3.2.3.发现3x版本 ...
 - ca78a_c++_字符串流在内存中的输入输出(速度快)
		
/*ca78a_c++_字符串流在内存中的输入输出**字符串流:在内存中的输入输出.(在内存中进行,速度快)**文件流 :是对文件进行输入和输出.(在磁盘里面进行)istringstream(输入), ...
 - Linux Shell 编程中的特殊符号
		
一.井号 # 1.在脚本文件中对一行进行注释. 2.在引号和\符号后不是注释,只是#号本身: echo "12 # hehe" echo '12 # hehe' echo 12 \ ...
 - Shell编程中Shift的用法
		
Shell编程中Shift的用法 位置参数可以用shift命令左移.比如shift 3表示原来的$4现在变成$1,原来的$5现在变成$2等等,原来的$1.$2.$3丢弃,$0不移动.不带参数的shif ...
 - Shell编程中while与for的区别及用法详解【转】
		
在shell编程中经常用到循环,常用的循环有for和while循环两种.while循环默认以行读取文件,而for循环以空格读取文件切分文件,本篇就结合现网的一些使用示例说说二者的用法和区别. 一.常用 ...
 - Linux Shell编程中的几个特殊符号命令 & 、&& 、 ||
		
https://blog.csdn.net/hack8/article/details/39672145 Linux Shell编程中的几个特殊符号命令 & .&& . || ...
 - shell编程中的if语句
		
if语句在任何编程中都是必不可少.至关重要的分支语句,shell也是如此,只不过各种编程中的方式和格式有点不太一样 shell编程中的if语句基本格式如下: if [ X$1 = XA ];then ...
 - shell编程中如何执行oracle语句
		
shell编程中如果向oracle中插入数据之类的,需要先把执行语句放到文件中,然后再@这个文件执行 有如下俩种方式供参考: SQL=`sqlplus user/pwd@orains << ...
 
随机推荐
- Reflection01_获取Class对象
			
1.java 代码: package reflectionZ; public class TreflectionZ { public static void main(String[] args) t ...
 - angularjs1 自定义轮播图(汉字导航)
			
本来想用swiper插件的,可是需求居然说要汉字当导航栏这就没办法了,只能自己写. directive // 自定义指令: Home页面的轮播图 app.directive('swiperImg', ...
 - java-ConcurrentLinkedQueue 简单使用
			
import java.util.concurrent.ConcurrentLinkedQueue; public class CacheTest { /** * * offer(E e) 将指定元素 ...
 - python学习笔记(unittest)
			
刚刚放假回来我想很多人都还没有缓过来吧 这次介绍一个python自带的测试框架 unitest #!/usr/bin/env python # -*- coding: utf_8 -*- import ...
 - 通过Google Custom Search API 进行站内搜索
			
今天突然想把博客的搜索改为google的站内搜索,印象中google adsense中好像提高这个站内搜索的代码,但苦逼的是google adsense帐号一直审核不通过,所以只能通过google c ...
 - day26 CRM search  && 增删改查
			
代码:https://github.com/liyongsan/git_class/tree/master/day26/LuffyCRM ORM查询之Q学习 http://www.cnblogs.co ...
 - opencv:傅里叶变换
			
示例代码: #include <opencv.hpp> #include <iostream> using namespace std; using namespace cv; ...
 - redux源码阅读之compose,applyMiddleware
			
我的观点是,看别人的源码,不追求一定要能原样造轮子,单纯就是学习知识,对于程序员的提高就足够了.在阅读redux的compose源码之前,我们先学一些前置的知识. redux源码阅读之compose, ...
 - *android判断手机号的运营商
			
TextView tv=(TextView)findViewById(R.id.tv); TelephonyManager telManager = (TelephonyManager) getSys ...
 - 请求URL中有body怎么使用jmeter进行接口测试
			
业务场景: 微信内免费领取激活码 1.点击“免费领取”按钮调取的接口 2.URL如下 https://yxyapi2.drcuiyutao.com/yxy-api-gateway/api/json/v ...