在bin下面有9个sh文件,本文将逐步分析,今天就以version.sh为例
os400=false #uname取操作系统名称 如Linux 如果为OS400的操作系统 特殊处理 case "`uname`" in OS400*) os400=true;; esac # resolve links - $0 may be a softlink # 解析文件或者符号文件 得到真正文件 # /home/dragonsuc/bin/version.sh # /home/dragonsuc/bin/tm ->/home/dragonsuc/bin/version.sh #当以符号连接启动时 找到真正文件/home/dragonsuc/bin/version.sh #取得当前执行文件名称 PRG="$0" #判断文件是否是符号文件 文件存在并且是符号文件 while [ -h "$PRG" ] ; do # lr 。。。。 /home/dragonsuc/bin/tm ->/home/dragonsuc/bin/version.sh ls=`ls -ld "$PRG"` # 注意下面两行中expr精妙用法 # 得到/home/dragonsuc/bin/version.sh link=`expr "$ls" : '.*-> (.*)$'` if expr "$link" : '/.*' > /dev/null; then PRG="$link" else PRG=`dirname "$PRG"`/"$link" fi done #得到目录路径 /home/dragonsuc/bin PRGDIR=`dirname "$PRG"` EXECUTABLE=catalina.sh # Check that target executable exists if $os400; then # -x will Only work on the os400 if the files are: # 1. owned by the user # 2. owned by the PRIMARY group of the user # this will not work if the user belongs in secondary groups eval else #测试文件的可执行权限 if [ ! -x "$PRGDIR"/"$EXECUTABLE" ]; then echo "Cannot find $PRGDIR/$EXECUTABLE" echo "The file is absent or does not have execute permission" echo "This file is needed to run this program" exit 1 fi fi # 执行文件 $@是传递执行的参数 exec "$PRGDIR"/"$EXECUTABLE" version "$@"