shell中test命令方法详解

请参考博客园:https://www.cnblogs.com/guanyf/p/7553940.html

test –e File                       文件存在

test –r File                       文件存在并且可读

事例如下

JENKINS_CONFIG=/etc/sysconfig/jenkins
test -e "$JENKINS_CONFIG" || { echo "$JENKINS_CONFIG not existing";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 6; fi; }
test -r "$JENKINS_CONFIG" || { echo "$JENKINS_CONFIG not readable. Perhaps you forgot 'sudo'?";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 6; fi; }

猜你喜欢

转载自www.cnblogs.com/faberbeta/p/linuxshell041.html