shell变量中再包含变量的情况!
2016-01-30 11:06
323 查看
#!/bin/bashERR_0="The $1 is exist!"ERR_1="The $1 is not exist!"function test(){ if [ -e $1 ] ; then return 0 else return 1 fi}test $1ret=$?eval result=\$ERR_$retecho $result
执行结果为:
CS> ./test.sh /root/test.sh
The /root/test.sh is not exist!
CS> ./test.sh /root/qx/test.sh
The /root/qx/test.sh is exist!
CS> ./test.sh /root/test.sh
The /root/test.sh is not exist!
CS> ./test.sh /root/qx/test.sh
The /root/qx/test.sh is exist!
通过上述方法,可以将错误码对应的输出来,已达到目的!
执行结果为:
CS> ./test.sh /root/test.sh
The /root/test.sh is not exist!
CS> ./test.sh /root/qx/test.sh
The /root/qx/test.sh is exist!
CS> ./test.sh /root/test.sh
The /root/test.sh is not exist!
CS> ./test.sh /root/qx/test.sh
The /root/qx/test.sh is exist!
通过上述方法,可以将错误码对应的输出来,已达到目的!
相关文章推荐
- Linux Shell编程进阶案例实战(三)
- Linux Shell零基础案例实战(二)
- linux shell编程零基础入门
- 企业Shell实战-MySQL分库分表备份脚本
- shell脚本(输出每个内存条的信息)
- 理论: 博弈2: 巴什博奕(Bash Game)
- Linux Bash 通配符
- 使用Shell 脚本防止SSH暴力破解
- Linux Bash 的基本功能 管道符
- Linux Bash的基本功能 输出重定向
- Linux 标准Shell Bash 的基本功能
- Linux 脚本执行方式 (Shell基础)
- SQL to mongo Shell to C++
- 【转载】MySQL被慢sql hang住了,用shell脚本快速清除不断增长的慢sql的办法
- shell特殊命令符
- shell特殊命令符
- shell特殊命令符
- shell特殊命令符
- shell特殊命令符
- shell特殊命令符