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. Accessing Scoped Variables

    To permit the JSP page to access the data, the servlet needs to use setAttribute to store the data i ...

  2. hdu 1116

    欧拉回路,利用并查集来实现: 代码: #include<cstdio> #include<cstring> #include<vector> using names ...

  3. 广州麒麟网络工作室 qlgame eninge(anroid) opengles c++ matrix

    在opengles中,采用的是可编程渲染管线,矩阵需要自己实现! 先说一下矩阵的理论: 参考一下资料:http://blog.sina.com.cn/s/blog_6084f588010192ug.h ...

  4. http://blog.csdn.net/dyllove98/article/details/7706218

    http://blog.csdn.net/dyllove98/article/details/7706218

  5. android 对象传输及parcel机制

    在开发中不少要用到Activity直接传输对象,下面我们来看看,其实跟java里面差不多   自定义对象的传递:通过intent传递自定义对象的方法有两个  第一是实现Serialization接口: ...

  6. Android Bitmap是不能比较的,这样做是错误的

    代码1: Bitmap dir = BitmapFactory.decodeResource(context.getResources(), R.drawable.netdisc_search_lis ...

  7. 简单的单页c#生成静态页源码

    protected void BtGroup_ServerClick(object sender, EventArgs e)        {            //产业群首页           ...

  8. constant

  9. DevExpress中XtraGrid控件对GridView每行的颜色设置 zt

    改变行颜色 private void GridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArg ...

  10. 迷宫城堡--HDOJ 1269(Tarjan)

    迷宫城堡 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...