fun() {
case $1 in
2)
return 2
;;
1)
return 1
;;
0)
return 0
;;
esac
}
想要跟据fun的返回值决定下一步做什么,应该怎么做呢?
[问题]在脚本中怎么看上一个命令的退出状态(exit status)?
- 5451vs5451
- 帖子: 345
- 注册时间: 2006-07-14 18:56
- 来自: Apple Valley, Planet Tux, Linux System
- laborer
- 帖子: 1016
- 注册时间: 2005-10-25 11:15
- 联系:
用$?,e.g.
代码: 全选
$ true; echo $?
0
$ false; echo $?
1
hreiser@oakland:~$ killall -9 wife
police@oakland:~$ sudo find / -user hreiser
court@oakland:~$ sudo mv /home/hreiser /jail/
court@oakland:~$ sudo usermod -d /jail/hreiser -s "/usr/sbin/chroot /jail/" hreiser
police@oakland:~$ sudo find / -user hreiser
court@oakland:~$ sudo mv /home/hreiser /jail/
court@oakland:~$ sudo usermod -d /jail/hreiser -s "/usr/sbin/chroot /jail/" hreiser
- 5451vs5451
- 帖子: 345
- 注册时间: 2006-07-14 18:56
- 来自: Apple Valley, Planet Tux, Linux System