您的位置:首页 > 运维架构 > Shell

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!

通过上述方法,可以将错误码对应的输出来,已达到目的!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: