1 #!/bin/sh 2 #echo "Hello# World !" 3 #your_name='qinjx' 4 #str="Hello, I know your are "$your_name"! " 5 #echo "英文${str}ohyes" 6 7 # 终端输入处理 8 read -p "请输入您的分数(0-100):" grade 9 10 # 合法性校验 11 if [ -z "$grade" ]; then 12 echo "您没有输入分数" 13 exit 14 15 #fi #这个是自己在网上找到添加的,因为输入字母就出错了 16 17 #if echo $grade | grep -q '[^0-9]' 18 #then 19 # echo "this is not a num,please input num" 20 # exit 21 fi 22 23 if [ $grade -gt "100" -o $grade -lt "0" ]; then 24 echo "您输入的分数不在0-100范围内" 25 exit 26 fi 27 # 计算等级 28 if [ $grade -ge "90" -a $grade -le "100" ]; then 29 echo "好极了,您的评分为: A" 30 elif [ $grade -ge "80" -a $grade -le "89" ]; then 31 echo "很好。您的评分为 B" 32 elif [ $grade -ge "70" -a $grade -le "79" ]; then 33 echo "好。您的评分为 C" 34 elif [ $grade -ge "60" -a $grade -le "69" ]; then 35 echo "不错。您的评分为 D" 36 elif [ $grade -lt "60" ]; then 37 echo "回去挨打吧" 38 fi
shell if....then,很好的一个学习代码,一眼就明白了
for循环
1 #!/bin/bash 2 #数字性循环 3 #第一种 4 for((i=1;i<=10;i++)); 5 do 6 echo $(expr $i * 3 + 1); 7 done 8 # 9 # 10 # 11 ##第二种 12 for i in $(seq 1 10) 13 do 14 echo $(expr $i * 3 + 1); 15 done 16 # 17 # 18 ##第三种 19 for i in {1..10} 20 do 21 echo $(expr $i * 3 + 1); 22 done 23 # 24 # 25 ##第四种 26 awk 'BEGIN{for(i=1; i<=10; i++) print i}' 27 # 28 # 29 ##字符性循环 30 ##第一种 31 for i in `ls`; 32 do 33 echo $i is file name! ; 34 done 35 # 36 ##第二种 37 for i in $* ; 38 do 39 echo $i is input chart! ; 40 done 41 # 42 # 43 ##第三种 44 for i in f1 f2 f3 ; 45 do 46 echo $i is appoint ; 47 done 48 # 49 ##第四种 50 list="rootfs usr data data2" 51 for i in $list; 52 do 53 echo $i is appoint ; 54 done 55 # 56 # 57 ##路径查找 58 ##第一种 59 for file in /home/cyl/下载/*; 60 do 61 echo $file is file path ! ; 62 done 63 # 64 ##第二种 65 for i in $(ls *.sh) 66 do 67 echo $file is file path ! ; 68 done