source和sh

写了一个脚本【xxyScript.sh】,用于判断tomcat是否启动

#!/bin/bash 
if [ -z "$(ps -ef | grep tomcat | grep -v 'grep tomcat' | awk -F ' ' '{print $2}'| awk -F ' ' '{print $1}')" ]; then 
    {
        echo "***************************the tomcat has shutdwon , I want to startp it******************************";
        sleep 3; 
        #//home/tomcat/tomA/bin/startup.sh; 
        echo "****************************the tomcat has startp ,and you can look tomA_log for it************************************";
        sleep 3; 
        #tail -f /home/tomcat/tomA/logs/catalina.out;
    }
fi
if [ -n "$(ps -ef | grep tomcat | grep -v 'grep tomcat' | awk -F ' ' '{print $2}'| awk -F ' ' '{print $1}')" ]; then 
    {
        echo "*************************the tomcat is startp************************************";
    }
fi 
然后使用命令执行:sh /home/tomcat/xxyScript.sh  ,如下图提示
然后使用命令: source /home/tomcat/xxyScript.sh ,如下图提示,说明了脚本被正常执行了
 
在找度娘后,看到有人解释:
原因是source就是直接在本shell下执行,直接读取脚本中命令行并执行,而sh则是新建了一个子shell,然后运行脚本

 

posted @ 2016-07-26 12:03  xxyBlogs  阅读(209)  评论(0编辑  收藏  举报