shell - Is trap EXIT required to execute in case of SIGINT or SIGTERM received? -


i have simple script

trap 'echo exit' exit while true; sleep 1; done 

and behaves differently in different shells:

$ bash tst.sh ^cexit $ dash tst.sh ^c $ zsh tst.sh ^c $ sh tst.sh ^cexit 

so i'm not sure how should operate , whether specified @ all.

the exit trap isn't working same way in every shell. few examples:

  • in dash , zsh it's triggered regular exit within script.
  • in zsh, if trap signal quit execution, need restore default behaviour explicitly calling exit.

i'd suggest catch signals , exit, should portable across shells:

$ cat trap trap 'echo exit; exit' int term  # , other signals while true; sleep 1; done $ bash trap ^cexit $ dash trap ^cexit $ zsh trap ^cexit $ ksh trap ^cexit $ mksh trap ^cexit $ busybox sh trap ^cexit 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -