#!/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!