別のスクリプトを実行してスクリプトを終了する

別のスクリプトを実行してスクリプトを終了する

私のスクリプトには次の条件があります。

if [[ "${SUMAN_ENV}" != "local" ]]; then
 ./suman.sh $@  # run this script instead
 # need to exit here
fi

条件が満たされたら、別のスクリプトを実行したいと思います。

最善の方法は次のようにすることです。

if [[ "${SUMAN_ENV}" != "local" ]]; then
 ./suman.sh $@
 exit $?  # exit with the code given by the above command
fi

それとも別の方法がありますか?

ベストアンサー1

文書hello:

#!/bin/sh
echo "$0"
exec ./world
echo "$0"

文書world:

#!/bin/sh
echo "$0"
exit 33 # to have an exit code example                                                                

ランニングhello:

$ ./hello 
./hello
./world
$ echo $?
33

helloworldviaが実行されexec完了した後、world残りはhello実行されません。終了コードは1ですworld

おすすめ記事