1.命令执行顺序判断
- | 衔接两个命令 ,
- && ||
- ; 前⾯执⾏的成功与否,与后⾯没有任何的关系,
- && 与 前⾯命令执⾏成功了,后⾯才执⾏
- || 或 前边命令执行成功了,后面就不执行
[root@localhost ~]# cd test/ && rm -rf ./* && mkdir 888.sh && ll
总用量 0
drwxr-xr-x. 2 root root 6 11月 7 13:18 888.sh
[root@localhost test]# cd
[root@localhost ~]# cd te || cd test/ || ls
bash: cd: te: 没有那个文件或目录
[root@localhost test]# cd te ; cd test ; ls
bash: cd: te: 没有那个文件或目录
bash: cd: test: 没有那个文件或目录
888.sh
[root@localhost test]# cd test | ls |sl |ll
总用量 0
drwxr-xr-x. 2 root root 6 11月 7 13:18 888.sh
bash: cd: test: 没有那个文件或目录
bash: sl: 未找到命令...
相似命令是: 'ls'
[root@localhost test]#
2.if语句
if语句结构:
if [ command ];then
符合该条件执⾏的语句
elif [ command ];then
符合该条件执⾏的语句
elif 【cammand】;then
else
符合该条件执⾏的语句
fi
int类型判断
1、-gt:大于,greater than。
2、-eq:等于,equal。
3、-lt:小于,less than。
4、-ge:大于等于,greater than or equal。
5、-le:小于等于,less than or equal。
6、-ne:不等于,not equal。
string类型判断
==,= 等于
实战演练:
主机是否在线脚本:
#!/bin/bash
myping(){
ping -c 1 -w1 $1 &>/dev/null
num=$?
if [ $num -eq 0 ];then
echo "$1 is up"
else
echo "$1 is down "
fi
}
for i in {1..25}
do
myping 192.168.1.$i
done
执行方法:
./ipTest.sh #测试此IP
sh -x ipTest.sh #显示执行过程