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. VIM一些常用命令,方法,配置

    配置文件地址 github 工具只是为了更好的工具,选择一种,坚持使用学习记忆,熬过瓶颈期就可以了. 现在我基本大的项目是IDE+vim 插件,写小代码是VIM. 常用的操作,便捷的方法 1.如何选中 ...

  2. 根据WSDL生成代理类方式(2)

    运行开发人员工具提示 输入命令行svcutil http://localhost:8080/Test/TestClassPort?wsdl

  3. ubuntu 安装mysql及修改编码

    643  netstat -tap | grep mysql  645  apt-get install mysql-server mysql-client  646  netstat -tap | ...

  4. PS字体工具字体显示不出来

    显示一个小点:搜索了各种答案,扩大字号(最大72)更改前景色和背景色,最正确的解释就是分辨率太低,我发现分辨率是1,一般的设置成300,1分辨率情况下可以在图层那选择文字图层,然后按ctrl+t,拉大 ...

  5. BZOJ 1754: [Usaco2005 qua]Bull Math

    Description Bulls are so much better at math than the cows. They can multiply huge integers together ...

  6. hdu 1116

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

  7. 解决qt5窗口不刷新(测试窗口类型,测试窗口属性)

    QApplication::notify #if QT_VERSION >= 0x050000        if (QEvent::Show == pEvent->type())     ...

  8. QT类库与Delphi类库的体系结构对比——两者十分类似!

    今天在看QT对象内存管理的一篇文章时:http://blog.csdn.net/dbzhang800/article/details/6300025想到了一个问题:就是QT类库体系结构与Delphi类 ...

  9. USACO3.42American Heritage(二叉树)

    已知中前 求后序 递归一下 有一些小细节 /* ID: shangca2 LANG: C++ TASK: heritage */ #include <iostream> #include& ...

  10. USACO3.32Shopping Offers(DP)

    五维DP,听着挺多的,貌似就是挺裸的dp, 最近貌似做简单的DP挺顺手..1A dp[i][j][e][o][g] = min(dp[i][j][e][o][g],dp[i-i1][j-i2][e-i ...