linux exit命令学习


linux exit命令学习
 
linuxexitshell退出码
exit命令有两个作用:
1. 退出当前shell
sh-# exit
exit
INIT: Entering runlevel: 3
 
2. 在shell script中直接退出,这样我们写shell scripts时就可以借助于特定的
退出码来表示scripts的执行状况。
sh-# touch /test_exit.sh
sh-# cat /test_exit.sh
#!/bin/sh
exit 127
 
sh-# ls -l /test_exit.sh
-rwxr-xr-x 1 root root 24 Jan  1 00:04 /test_exit.sh
sh-# $?
sh: 0: command not found
sh-# /test_exit.sh
sh-# $?
sh: 127: command not found
sh-# echo "exit 126" > /test_exit.sh
sh-# cat /test_exit.sh
exit 126
sh-# /test_exit.sh
sh-# $?
sh: 126: command not found
sh-# vim
sh: vim: command not found
sh-# $?
sh: 127: command not found
 
关于退出码的约定:
通常0,表示命令执行成功;
非0,表示命令执行失败。

相关内容

    暂无相关文章