# showCfile.sh iftest -d $HOME/a_sub then echo"-- the .c and .obj files in $HOME/a_sub: --" for filename in `ls$HOME/a_sub` do case$filenamein *.c) echo$filename;; *.obj) echo$filename;; esac done else echo"$HOME/a_sub does not exist!!" fi iftest -d $HOME/b_sub then echo"--- the .c and .obj files in $HOME/b_sub: ---" for filename in `ls$HOME/b_sub` do case$filenamein *.c) echo$filename is a C source file!;; *.obj) echo$filename is an Object file!;; esac done else echo"$HOME/b_sub does not exist!!" fi
1 2 3 4 5 6 7
while [test -r abc.txt] do echo"file abc.txt has not beed deleted !“ sleep 10 done echo "file abc.txt has beed deleted !"
1 2 3 4 5 6 7 8
count=0 whileread LINE do count=`expr$count + 1` done < file echo$count 或者 cat file | wc -l
echo echo"--- Disk Usage Condition ---" used_disk=`du -s /home | cut -f1` echo"Used Blocks: $used_disk" free_disk=`df | head –2 |tail -1 | tr -s "[ ]" | cut -f4 -d" "` echo"Free Blocks: $free_disk" total_disk=`expr$used_disk + $free_disk` echo"total blocks:$total_disk" echo echo"--- disk usage ratio ---" #计算出磁盘的利用率 ratio=`echo"scale=6; $used_disk*100/$total_disk" | bc` echo -e "usage ratio: $ratio%" if [ `expr"$ratio < 50"` ] then echo"用户文件系统磁盘使用负荷小" elif [ `expr"$ratio > 90"`] then echo"用户文件系统磁盘使用负荷偏大" else echo"用户文件系统磁盘使用负荷正常" fi echo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
echo -e "Please enter the score:" whileread SCORE do case$SCOREin ?|[1-5]? ) echo"Failed!" echo"Please enter the next score:";; 6?) echo"Passed!" echo"Please enter the next score:";; 7?) echo"Medium!" echo"Please enter the next score:";; 8?) echo"Good!" echo"Please enter the next score:";; 9?|100) echo"Great!" echo"Please enter the next score:";; *) exit;; esac done
ans=y until [ "$ans" = n ] do echo"Enter a Student number:" read number echo The inputed number is:${number}
count=`grep ${number} score.dat | wc -l` echo the Count found is ${count} iftest"$count" -eq 1 then score=`grep ${number} score.dat | cut -d\| -f2` echo The score is: ${score} else echo"Can not found this number !!" fi
echo"Continue?" echo"Enter y(yes) or n(no)" read ans done