http://www.gnu.org/software/bash/manual/bashref.html#Redirections

http://www.cnblogs.com/weidagang2046/p/io-redirection.html 原理与实现

http://blog.csdn.net/taiyang1987912/article/details/39401265

[root@server1 tmp]# cd /dev/fd
[root@server1 fd]# ll
总用量 0
lrwx------ 1 root root 64 6月 4 12:17 0 -> /dev/pts/0
lrwx------ 1 root root 64 6月 4 12:17 1 -> /dev/pts/0
lrwx------ 1 root root 64 6月 4 12:17 2 -> /dev/pts/0
lrwx------ 1 root root 64 6月 4 12:17 255 -> /dev/pts/0

#使用exec将stdin重定向到文件
#!/bin/bash exec <& #FD 8是FD 0的副本,用于恢复标准输入
exec < file #将标准输入重定向到file
read a #读取file的第一行
read b #读取file的第二行
echo "read has read $$"
echo "read has read $PPID"
sleep
echo "----------------"
echo $a #标准输出
echo $b #标准输出 该进程的文件描述符FD 变为如下

[root@server1 fd]# ll
总用量 0
lr-x------ 1 root root 64 6月 4 13:03 0 -> /root/file
lrwx------ 1 root root 64 6月 4 13:03 1 -> /dev/pts/0
lrwx------ 1 root root 64 6月 4 13:03 2 -> /dev/pts/0
lr-x------ 1 root root 64 6月 4 13:03 254 -> /root/a.sh
lrwx------ 1 root root 64 6月 4 13:03 255 -> /dev/pts/0
lrwx------ 1 root root 64 6月 4 13:03 8 -> /dev/pts/0

echo "close FD 8:"
exec 0<&8 8<&- #将FD 8复制到FD 0,恢复FD 0,并关闭FD 8,其他进程可以重复使用FD 8
echo -n "Enter Data:"
read c #read从标准输入读取数据
echo $c
echo $$
echo $PPID
sleep 100

[root@server1 4598]# ll fd
总用量 0
lrwx------ 1 root root 64 6月 4 13:11 0 -> /dev/pts/0
lrwx------ 1 root root 64 6月 4 13:11 1 -> /dev/pts/0
lrwx------ 1 root root 64 6月 4 13:11 2 -> /dev/pts/0
lr-x------ 1 root root 64 6月 4 13:11 254 -> /root/a.sh
lrwx------ 1 root root 64 6月 4 13:11 255 -> /dev/pts/0

 
#eval重新提交shell
#!/bin/bash while read NAME VALUE #第一列作为变量名,第二列作为变量值 //对应文件中的两列
do
eval "${NAME}=${VALUE}" #第1轮变量替换,eval重新提交shell完成赋值操作
done < evalsource #输入重定向
echo "var1=$var1" #变量赋值
echo "var2=$var2"
eval "${NAME}=${VALUE}" 为一段可执行的命令,而不是字符串

[root@server1 ~]# eval "cc=100"
[root@server1 ~]# echo $cc
100

[root@server1 ~]# echo "dd=100"
dd=100


[root@server1 ~]# x=
[root@server1 ~]# ptrx=x
[root@server1 ~]# eval echo \$$ptrx [root@server1 ~]# eval $ptrx=
[root@server1 ~]# echo $x [root@server1 ~]# echo $ptrx
x

bash手册 之重定向原理与实现的更多相关文章

  1. bash手册

    目录 bash手册 man命令 man man 分页程序(page) Linux手册页惯用的节名 Linux手册页的内容区域 查看命令在Linux手册页中的区域 info页面 help帮助 bash手 ...

  2. SpringMVC学习手册(一)------工作原理解析

    1.什么是MVC模式 图解:   2.SpringMVC原理图解:       springMVC中的几个组件: 前端控制器(DispatcherServlet):接收请求,响应结果,相当于电脑的CP ...

  3. bash帮助文档简单学习;bash手册翻译

    关于bash的四种工作方式的不同,可以参考:http://feihu.me/blog/2014/env-problem-when-ssh-executing-command-on-remote/,但是 ...

  4. python重定向原理及实例

    1. 前言 为了在Python编程中, 利用控制台信息, 我们需要对控制台输出进行接管(重定向).在Python中,控制台输出的接口是sys.stdout,通过分析print与sys.stdout之间 ...

  5. Spring Security 重定向原理分析

    本文基于 spring-security-core-5.1.1 和 tomcat-embed-core-9.0.12. 一个用户访问使用表单认证的 Web 应用时,后端的处理流程大致如下: 1.用户访 ...

  6. Linux编程 3 (初识bash shell与man查看手册)

    一.初识bash shell 1.1 启动 shell   GNU bash shell 能提供对Linux系统的交互式访问.通常是在用户登录终端时启动,登录时系统启动shell依赖于用户账户的配置. ...

  7. 浅谈输入输出”重定向“——基于Linux系统

    前言 进程在启动后会自动的打开3个文件:标准输入.标准输出和标准错误输出分别对应文件描述符0.1.2.对于每个进程他们都都维护了一张文件描述符表(file descriptor table),通常fd ...

  8. bash脚本编程之二 字符串测试及for循环

    shell中大量的测试和比较选项而困惑呢? 这个技巧可以帮助您解密不同类型的文件.算术和字符串测试,这样您就能够知道什么时候使用 test. [ ]. [[ ]].(( )) 或 if-then-el ...

  9. 【转】Linux 技巧: Bash 参数和参数扩展

    重点看下清单7 现在,很多 Linux® 和 UNIX® 系统上都有 bash shell,它是 Linux 上常见的默认 shell.通过本文,您将了解到如何在 bash 脚本中处理参数和选项,以及 ...

随机推荐

  1. virtualBox ubuntu 文件共享

    如何将主机中的文件共享到虚拟机中: 1.  查看/dev中的文件  命令:ls /dev 2.  找到 cdrom1 ,直接挂载到/mnt 命令:sudo mount /dev/cdrom1 /mnt ...

  2. java 堆与栈的区别

    1. 堆与栈的区别? 1-1. 数据存放位置:   数据都存放于RAM (Random Access Memory). 1-2. 存放数据的类型:stack栈中保存方法中的基本数据类型(int, do ...

  3. jquery多级手风琴插件–accordion.js

    手风琴菜单一般用于下拉导航,由于外观非常简洁,使用起来跟手风琴一样可以拉伸和收缩而得名,项目中适当应用手风琴效果会给用户带来非常好的体验.本文借助jQuery插件轻松打造一个非常不错的手风琴效果的菜单 ...

  4. 【技术贴】Maven打包文件增加时间后缀

    构建war包,或者jar包的,时候,maven会自动增加一个版本号和时间放在jar包后面比如poi-3.9-20131115.jar这样子,但是我自己打war包,总是给我生成一个快照的后缀report ...

  5. uva 12526 - Cellphone Typing

    字典树,可惜比赛的时候有两句话写倒了: 害得我调了一个小时: 今天不宜做题 = = 代码: #include<cstdio> #include<cstring> #define ...

  6. GSM、GPRS、EDGE、2G、3G与WAP的关系

    1.GSM(Global System of Mobile communication)即全球移动通讯系统: 是目前使用人数最大的移动通信网络,就是2G的移动通信技术,是一种电路交换系统.这种网络仅提 ...

  7. 李洪强漫谈iOS开发[C语言-029] - 关系运算符

  8. openCV python 安装

    0, 用 import cv 测试,发现没有安装 opencv 模块. 首先先说本开发环境是在windows xp的环境下进行搭建的. 在搭建的过程中需要保证这三个条件: 1.python需要安装py ...

  9. 使用C#画图(饼图折线图)

    public PlaceHolder PlaceHolder1; //显示图像的控件 各个图像的类别名称如下: PictureType    图形种类    5    chChartTypeBarCl ...

  10. PowerDesigner 的常用小技巧 转

    中小 订阅 修改外键命名规则 选择Database—>Edit Current DBMS选择Scripts->Objects->Reference->ConstName可以发现 ...