#!/bin/bash
read -p "请输入一个字符:" a
if [ -z $a ];then
echo "请输入数字"
exit
fi
echo $a | grep -qE '[0-9]+'
n1=$?
if [ $n1 -eq 0 ];then
echo "输入的是整数"
fi
#!/bin/bash
read -p "请输入一个字符:" a
if [ $a -eq 1 ];then
echo "this is ok"
elif [ $a -eq 2 ];then
echo "this is fuck"
else
echo "this is over"
fi
for 循环
#!/bin/bash
for i in {1,2,3,4,5}
do
echo $i
done
#!/bin/bash
for i in `seq 1 9 `
do
str=""
for j in `seq 1 9 `
do
if [ $j -gt $i ];then break
fi
let num=$i*$j
str="$str$num \t"
done
echo -e $str
done
#!/bin/bash
array=("zhangsan" "lisi" "wangwu")
for ((i=0;i<${#array[@]};i++))
do
echo ${array[i]}
done
#!/bin/bash
for ((i=0;i<5;i++))
do
echo $i
done
case用法
#!/bin/bash
read -p "请输入数字:" a
if [[ -z $a ]];then
echo "请输入数字"
fi
case $a in
3)
echo "fuckyou"
;;
4)
echo "shit"
;;
5)
echo "get out"
;;
*)
echo "over"
esac
while用法
#!/bin/bash
SUM=0
i=0
while [[ $i -le $1 ]]
do
SUM=$(($SUM+$i))
i=$(( $i+1 ))
done
echo $SUM
#!/bin/bash
SUM=0
i=0
while [[ $i -le $1 ]]
do
SUM=$[SUM+i]
i=$[i+1]
done
echo $SUM
#!/bin/bash
SUM=0
i=0
while [[ $i -le $1 ]]
do
let SUM=SUM+i
let i=i+1
done
echo $SUM