标签:
单片机与嵌入式系统考试Shell编程题库,简单地做了下。
9. 与题7类似,多了个乘法运算。
#!/bin/bash # test1.sh # 2016.1.2 echo "Please input N student grade:" read -a grade for ((i=0;i<${#grade[@]};i++)) do if [[ ${grade[i]} -ge 90 ]] then grade[i]=5 elif [[ ${grade[i]} -ge 80 ]] then grade[i]=4 elif [[ ${grade[i]} -ge 70 ]] then grade[i]=3 elif [[ ${grade[i]} -ge 60 ]] then grade[i]=2 else grade[i]=1 fi done #echo ${grade[*]} echo ${grade[*]} > score.dat
#!/bin/bash # test2.sh # 2016.1.2 echo "Please input N number:" read -a arr for ((i=0;i<${#arr[@]};i++)) do for ((j=${#arr[@]}-1;j>i;j--)) do if [[ ${arr[j]} -lt ${arr[j-1]} ]] then t=${arr[j]} arr[j]=${arr[j-1]} arr[j-1]=$t fi done done echo ${arr[*]} > result.dat
#!/bin/bash # test3.sh # 2016.1.2 cd /home if test -e tesh.sh then rm tesh.sh else touch tesh.sh fi
#!/bin/bash # test4.sh # 2016.1.2 if [ -z "$1" ] then echo "You should input N num!" exit 1 fi max=$1 min=$1 for num in $* do if [ $num -gt $max ] then max=$num fi if [ $num -lt $min ] then min=$num fi done echo "Max: $max , Min: $min"
#!/bin/bash # test5.sh # 2016.1.2 j=0; for ((i=1;i<=100;i++)) do j=`expr $i + $j` done echo $j
#!/bin/bash # test6.sh # 2016.1.2 echo "Input 1 char:" read a if [ $a = ‘Y‘ ] then echo "right!" elif [ $a = ‘N‘ ] then echo "wrong!" else echo "bad input!" fi
#!/bin/bash # test7.sh # 2016.1.2 echo "Input 2 Number:" read a read b echo "Input + or - :" read op if [ $op = ‘+‘ ] then x=`expr $a + $b` elif [ $op = ‘-‘ ] then x=`expr $a - $b` fi echo $x
#!/bin/bash # test8.sh # 2016.1.2 cd /home if test -d exam then rm -r exam else mkdir exam fi
#!/bin/bash # test9.sh # 2016.1.2 echo "Input 2 Number:" read a read b echo "Input + or - or x:" read op if [ $op = ‘+‘ ] then x=`expr $a + $b` elif [ $op = ‘-‘ ] then x=`expr $a - $b` elif [ $op = ‘x‘ ] then x=`expr $a \* $b` fi echo $x
OK!
标签:
原文地址:http://www.cnblogs.com/ht-beyond/p/5095159.html