shell 循环变量传递问题
来源:互联网 发布:华为手机root软件 编辑:程序博客网 时间:2024/05/22 01:46
如例子中:
#!/bin/bashfile="/etc/passwd"let num=0cat $file | while read linedo echo -e "hello,`echo $line|cut -d ":" -f 1` \c" echo your UID is `echo $line|cut -d ":" -f 3` num=$[$num+1] echo $numdoneecho number is $num
执行结果如下(后面一部分)
hello,hplip your UID is 11332hello,saned your UID is 11433hello,lsn your UID is 100034hello,sshd your UID is 11535number is 0
定义为环境变量没有用的,环境变量只是在子进程创建的时候可以从父进程复制到子进程,它无法实现从子进程往父进程传递,也不能在子进程运行期间从父进程获得新值。
解决办法是不要产生子进程
如下:
#!/bin/bashfile="/etc/passwd"let num=0while read linedo echo -e "hello,`echo $line|cut -d ":" -f 1` \c" echo your UID is `echo $line|cut -d ":" -f 3` num=$[$num+1] echo $numdone < $fileecho number is $num
执行结果:
hello,speech-dispatcher your UID is 11231hello,hplip your UID is 11332hello,saned your UID is 11433hello,lsn your UID is 100034hello,sshd your UID is 11535number is 35
1 0
- shell 循环变量传递问题
- Shell变量传递
- shell awk 变量传递
- Shell变量while循环内改变无法传递到循环外
- shell 变量 判断 循环
- Bash shell,while 循环中的变量无法保存问题
- shell循环中变量的作用域问题
- shell 参数传递、判断、循环
- pthread_create 参数传递指针问题(创建多线程时,循环变量的传递)
- SQLPLUS 向SHELL传递变量
- SHELL : 将shell变量传递给awk
- kettle变量传递问题
- shell while循环问题
- shell 默认变量问题
- shell变量问题
- Shell 间接变量问题
- json传递死循环问题
- shell & awk 变量传递+awk综合概要
- 【opencv】多边形检测
- InputSteam源码分析
- Android动态加载Activity原理
- 随机10个数和 二
- 基于形态学分水岭的分割
- shell 循环变量传递问题
- 去哪儿-首个重复字符
- Linux下tomcat启动Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of
- OA中BaseDao抽象设计思路梳理
- ARM汇编指令学习 - 实现数据块的拷贝复制
- CentOS 6.5 Web环境配置
- LeetCodet题解--17. Letter Combinations of a Phone Number(所有数字键盘组合所对应的所有字符集合)
- MySQL数据导出与导入
- 安卓简单的POST和GET请求