
私のスクリプトには次の条件があります。
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
hello
world
viaが実行されexec
完了した後、world
残りはhello
実行されません。終了コードは1ですworld
。