Return an exit code without closing shell

前端 未结 5 1090
后悔当初
后悔当初 2021-01-01 12:39

I\'d like to return an exit code from a BASH script that is called within another script, but could also be called directly. It roughly looks like this:

#!/b         


        
5条回答
  •  孤独总比滥情好
    2021-01-01 13:12

    Another option is to use a function and put the return values in that and then simply either source the script (source processStatus.sh) or call the script (./processStatus.sh) . For example consider the processStatus.sh script that needs to return a value to the stopProcess.sh script but also needs to be called separately from say the command line without using source (only relevant parts included) Eg:

    check_process ()
    {
      if [ $1 -eq "50" ]
      then
        return 1       
      else
        return 0
      fi       
    }
    

    and

    source processStatus.sh $1
    RET_VALUE=$?
    if [ $RET_VALUE -ne "0" ]
    then
      exit 0
    fi
    

提交回复
热议问题