exit命令用于退出当前shell,在shell脚本中可以终止当前脚本执行。

常用参数
格式:exit n
退出。设置退出码为n。(Cause the shell to exit with a status of n.)

格式:exit
退出。退出码不变,即为最后一个命令的退出码。(If n is omitted, the exit status is that of the last command executed. )

格式:$?
上一个命令的退出码。

格式:trap "commands" EXIT
退出时执行commands指定的命令。( A trap on EXIT is executed before the shell terminates.)

退出码(exit status,或exit code)的约定:
0表示成功(Zero - Success)
非0表示失败(Non-Zero - Failure)
2表示用法不当(Incorrect Usage)
127表示命令没有找到(Command Not Found)
126表示不是可执行的(Not an executable)
>=128 信号产生

 

参考:

https://www.cnblogs.com/itcomputer/p/4157859.html

 

相关文章:

  • 2022-12-23
  • 2021-09-27
  • 2021-06-23
  • 2021-10-11
  • 2021-09-19
  • 2022-02-23
  • 2021-09-19
  • 2021-08-22
猜你喜欢
  • 2021-12-26
  • 2022-12-23
  • 2021-09-27
  • 2021-06-10
  • 2022-12-23
相关资源
相似解决方案