shell 脚本里的$?
发表于 : 2010-07-29 23:41
shell脚本里的$?网上查了是说关于程序执行后返回的结果
但不知道是什么结果,是指错误结果,还是正常执行结果,
假如脚本里有一个ping命令,用$?怎么知道有没有ping通
请大家指教一下,谢谢!
但不知道是什么结果,是指错误结果,还是正常执行结果,
假如脚本里有一个ping命令,用$?怎么知道有没有ping通
请大家指教一下,谢谢!
代码: 全选
Fan:~/Desktop$ping -c 3 www.baidu.com
PING www.a.shifen.com (202.108.22.5) 56(84) bytes of data.
64 bytes from xd-22-5-a8.bta.net.cn (202.108.22.5): icmp_seq=1 ttl=55 time=49.3 ms
64 bytes from xd-22-5-a8.bta.net.cn (202.108.22.5): icmp_seq=2 ttl=55 time=48.0 ms
64 bytes from xd-22-5-a8.bta.net.cn (202.108.22.5): icmp_seq=3 ttl=55 time=48.4 ms
--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 48.054/48.625/49.381/0.585 ms
Fan:~/Desktop$echo $?
0
Fan:~/Desktop$ping -c 3 www.baidu.comm
PING www.baidu.comm (220.250.64.24) 56(84) bytes of data.
--- www.baidu.comm ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 2015ms
Fan:~/Desktop$echo $?
1
代码: 全选
tlcr: 0 庚寅年六月十九日 00:31:55 ~
>> ls
Apps Dropbox Private Share 个人 共享 应用
tlcr: 0 庚寅年六月十九日 00:31:59 ~
>>