#!/usr/bin/bash
#比较命令test,满足执行then,fi代表条件判断结束
#字符串比较
echo "input"
read a
if test "hello" = "$a"
then
echo "=="
fi
#第二种方式
if [ "hello" = "$a" ]
then
echo "=="
fi
#满足条件与不满足条件都有输出
#算数比较,判读是否大于-gt,判断是否大于等于-ge
if [ "$a" -gt 10 ]
then
echo "$a > 10"
else
echo "$a <= 10"
fi
#文件条件测试
#判读是否为目录文件-d+文件名,判读是否为普通文件-f+文件名
if [ -d "$a" ]
then
echo "$a is dirent"
elif [ -f "$a ]
then
echo "$a is file"
else
echo "$a not exist"
fi
i=0
#让变量自增
let "i+=1"
#expr表示执行算数运算符
i=`expr $i + 1`
echo "i=$i"
#如果要执行将ls这个命令,得加个括号,不然ls就是一个普通的变量,其他命令也是如此
str=$(ls)
echo "str=$str"
exit 0
3.循环
#循环有3中
#1.for循环,一般用于有限个值的操作
for filename in $(ls)
do
echo "$filename"
sleep 1
done
#2.while循环
#while condition do states
#done
#while [ : ] 死循环
while [ "1" == "1" ]
do
echo "run"
sleep 1
done
#3.until循环,当condition不成立时循环,知道检测到一个东西的时候停止
#until condition do statements done
exit 0