linux中的echo $?使用小技巧 211006
linux中的echo $?使用小技巧
[root@centos8 ~]#curl http://www.wangxiaochun.com/testdir/hello.sh 2> /dev/null |bash
hello, world
Hello, world!

远程调试bash
[root@centos8 ~]#wget -qO - http://www.wangxiaochun.com/testdir/hello.sh |bash
hello, world
Hello, world!

判断网络是否通畅
[root@rocky8 ~]#ping -c1 www.baidu.com &> /dev/null
[root@rocky8 ~]#echo $?
0

判断是否存在账号
[root@rocky8 ~]#id kevin &> /dev/null
[root@rocky8 ~]#echo $?
0
[root@rocky8 ~]#id kevinma &> /dev/null
[root@rocky8 ~]#echo $?
1

浙公网安备 33010602011771号