shell小记:eval
来源:互联网 发布:ios 单向链式编程 编辑:程序博客网 时间:2024/05/29 12:58
shell在执行命令的时候,有一些符号需要shell能够直接能够看到的,例如管道 |,重定向 (>, <, >>, <<)等,所以此时如果有以下语句:
#! /bin/bashpipe="|"ls /home/ $pipe grep "out"按照我们的想法, ls /home/ $pipe grep "out"实质就是 ls /home/ | grep "out",该语句是没有问题的,但是由于管道这些符号,shell需要能够直接在语句中看到,所以该语句执行会出现错误:
ls: cannot access |: No such file or directoryls: cannot access grep: No such file or directoryls: cannot access set: No such file or directory以上出现找不到 |,grep,set的错误
所以此时我们需要通过使用eval来解决该问题,eval添加到语句的开头,在执行该语句的时候,会扫描两次该语句:第一次扫描能够替换变量对应的值,第二次扫描就是为了识别语句并运行该语句,所以改为:
#! /bin/bashpipe="|"eval ls /home/ $pipe grep "out" #添加eval
0 0
- shell小记:eval
- shell eval
- [shell] eval
- shell小记
- shell 小记
- shell小记
- shell eval用法
- shell eval用法
- shell eval命令使用
- shell eval netstat awk
- shell eval 指令
- shell中的eval
- linux shell的eval
- shell中eval用法
- shell中的eval命令
- eval用法 【shell】
- shell之eval用法
- shell eval命令使用
- Java虚拟机(JVM)参数配置说明
- 单机版五子棋游戏项目的实现
- 元素在页面内上下居中的4种方法
- php编码
- VBScript把json字符串解析成json对象的2个方法
- shell小记:eval
- 在线学习网站
- Java isAssignableFrom 理解
- 最好的Python机器学习库
- C# 中自定义Attribute值的获取与优化
- java中常见的异常及处理方法
- JSeparator类 JPopupMenu类
- 意图 intent
- Android 播放mp3