返回外壳中的出口进程代码



我在.bash_profile

中具有此功能
function suman {
       LOCAL_SUMAN=$(node $HOME/.suman/find-local-suman-executable.js);
       if [ -z "$LOCAL_SUMAN" ]; then
           echo "No local Suman executable could be found, given the current directory => $PWD"
           return 1;
       else
           return node "$LOCAL_SUMAN" "$@";  # this is wrong I think
       fi
  } 

我只想返回节点进程的退出代码,但是我认为上面的行不正确,什么是从suman函数返回正确退出代码的正确方法?

我会猜测退出代码将被同一行的节点进程"返回"。

也许我应该删除返回关键字?

您在该行中不需要return;只需致电node "$LOCAL_SUMAN" "$@";由于这是您函数执行的最后一个命令,因此您的功能将以与node的呼叫相同的返回状态退出。

suman () {
   LOCAL_SUMAN=$(node $HOME/.suman/find-local-suman-executable.js)
   if [ -z "$LOCAL_SUMAN" ]; then
       echo "No local Suman executable could be found, given the current directory => $PWD"
       return 1
   else
       node "$LOCAL_SUMAN" "$@"
   fi
} 

最新更新