bash手册 之重定向原理与实现
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手册 之重定向原理与实现的更多相关文章
- bash手册
目录 bash手册 man命令 man man 分页程序(page) Linux手册页惯用的节名 Linux手册页的内容区域 查看命令在Linux手册页中的区域 info页面 help帮助 bash手 ...
- SpringMVC学习手册(一)------工作原理解析
1.什么是MVC模式 图解: 2.SpringMVC原理图解: springMVC中的几个组件: 前端控制器(DispatcherServlet):接收请求,响应结果,相当于电脑的CP ...
- bash帮助文档简单学习;bash手册翻译
关于bash的四种工作方式的不同,可以参考:http://feihu.me/blog/2014/env-problem-when-ssh-executing-command-on-remote/,但是 ...
- python重定向原理及实例
1. 前言 为了在Python编程中, 利用控制台信息, 我们需要对控制台输出进行接管(重定向).在Python中,控制台输出的接口是sys.stdout,通过分析print与sys.stdout之间 ...
- Spring Security 重定向原理分析
本文基于 spring-security-core-5.1.1 和 tomcat-embed-core-9.0.12. 一个用户访问使用表单认证的 Web 应用时,后端的处理流程大致如下: 1.用户访 ...
- Linux编程 3 (初识bash shell与man查看手册)
一.初识bash shell 1.1 启动 shell GNU bash shell 能提供对Linux系统的交互式访问.通常是在用户登录终端时启动,登录时系统启动shell依赖于用户账户的配置. ...
- 浅谈输入输出”重定向“——基于Linux系统
前言 进程在启动后会自动的打开3个文件:标准输入.标准输出和标准错误输出分别对应文件描述符0.1.2.对于每个进程他们都都维护了一张文件描述符表(file descriptor table),通常fd ...
- bash脚本编程之二 字符串测试及for循环
shell中大量的测试和比较选项而困惑呢? 这个技巧可以帮助您解密不同类型的文件.算术和字符串测试,这样您就能够知道什么时候使用 test. [ ]. [[ ]].(( )) 或 if-then-el ...
- 【转】Linux 技巧: Bash 参数和参数扩展
重点看下清单7 现在,很多 Linux® 和 UNIX® 系统上都有 bash shell,它是 Linux 上常见的默认 shell.通过本文,您将了解到如何在 bash 脚本中处理参数和选项,以及 ...
随机推荐
- C#中数据库连接的配置文件
在C#2010中,如何保存和访问数据库的连接字符串呢? 在Winform下要新增App.config文件,在Asp.net下要新增web.config文件. 1.打开配置文件添加相关代码后如下即可: ...
- 【HDU 5456】 Matches Puzzle Game (数位DP)
Matches Puzzle Game Problem Description As an exciting puzzle game for kids and girlfriends, the Mat ...
- 【BZOJ 1191】 [Apio2010]特别行动队 (斜率优化)
dsy1911: [Apio2010]特别行动队 [题目描述] 有n个数,分成连续的若干段,每段的分数为a*x^2+b*x+c(a,b,c是给出的常数),其中x为该段的各个数的和.求如何分才能使得各个 ...
- Ubuntu 安装基础教程
转自:http://teliute.org/linux/Ubsetup/index.html 1.进入 live cd 桌面 1)设置好启动后,断开网络,然后重启动计算机,可以用硬盘启动,也可以刻成 ...
- HTML Jquery;marquee标签
在<网页制作Dreamweaver(悬浮动态分层导航)>中,运用到了jQuery的技术,轻松实现了菜单的下拉.显示.隐藏的效果,不必再用样式表一点点地修改,省去了很多麻烦,那么jQuery ...
- Android开源项目发现---ListView篇(持续更新)
资料转载地址:https://github.com/Trinea/android-open-project 1. android-pulltorefresh 一个强大的拉动刷新开源项目,支持各种控件下 ...
- WebX配置文件、启动与响应流程
** 最近几天一直在看Spring的Ioc和AOP的源码介绍,还有Webx的使用.看Spring的源代码让人眼花缭乱,webx的配置文件也会让人感觉错综复杂无从下手.今天把之前看到的想到的webx相关 ...
- java学习多线程之创建多线程一
现在我们有这么一个需求,就是在主线程在运行的同时,我们想做其他的任务,这个时候我们就用到了多线程.那么如何创建多线程,我们知道在系统当中qq的多线程创建是由操作系统来完成的,那么如果我们想在java当 ...
- Node.js权威指南 (13) - 数据库访问
13.1 在MongoDB数据库中存取数据 / 360 13.1.1 MongoDB概述 / 360 13.1.2 安装MongoDB数据库 / 360 13.1.3 安装MongoDB包 / 361 ...
- (转载)Linux上iptables防火墙的基本应用教程
(转载)http://www.vpser.net/security/linux-iptables.html iptables是Linux上常用的防火墙软件,下面vps侦探给大家说一下iptables的 ...