我遇到一种情况,就是我把各种命令放在数组变量中,然后通过查表或者循环来执行这些命令。
现在问题简单化:
# a="echo hello"
# $a
hello
完美执行。OK
但是下面的情况:
# a="echo hello > a.txt"
# $a
hello > a.txt
这个结果就不是我想要的了?如何解决???
难题!把要执行的命令,存放在变量中,然后执行该变量。但是命令里面出现了>,情况就 ..........
- uusky
- 帖子: 159
- 注册时间: 2006-09-02 10:02
- uusky
- 帖子: 159
- 注册时间: 2006-09-02 10:02
Re: 难题!把要执行的命令,存放在变量中,然后执行该变量。但是命令里面出现了>,情况就 ..........
唉,算了。我自问自答了。
问题解决了。
# a="echo hello > a.txt"
# $a
hello > a.txt
# eval $a
# cat a.txt
hello
哈哈……
问题解决了。
# a="echo hello > a.txt"
# $a
hello > a.txt
# eval $a
# cat a.txt
hello
哈哈……