GOTOmsdos
铂金会员
C++启程者
积分 5154
发帖 1827
注册 2003-7-18
状态 离线
|
『楼 主』:
刚玩了玩控制语句,与大家共勉
刚装上RED HAT 9 初学SHELL 以下是控制语句的练习,与大家共勉:#!/bin/bash
cat<<EOF1
hello ! everybody who likes LINUX shell
here's a mini script test for LINUX shell as follows:
the first, enter two numbers (for us to see if they match our needs, as well),
and then choose one action from ADDING, SUBTRACTION
MULTIPLICATION and DIVISION. and finally you'll see the result
thank you for cooperation !
EOF1
sleep 2
cat<<EOF
if you want to view the shell script, enter "y"
(press SPACE to next page, PAGEUP to previous page, PAGEDOWN to next page
ARROWs to more or less lines, "q" to quit "view"
otherwise, enter "n"
EOF
read look
if [ $look == y ]
then
clear
less $0
else
echo "let's go ahead !"
fisleep 2
echo "please give first number, then press ENTER"
read num1
echo "please give second number, then press ENTER"
read num2
((sum=$num1+$num2))echo "the numbers you just put in are:"
for num in $num1 $num2
do
echo $num
done
sleep 3while [ $sum -le 1000 ]
do
clear
echo "the numbers you gave doesn't match our needs"
echo "you haven't passed obstacle 1"
echo "we have to start it again!"
sleep 10
$0
doneecho "congradulations! you've passed obstacle 1"
echo "let's go on"
sleep 2until [ $sum -ge 10000 ]
do
clear
echo "the numbers you gave still doesn't match our needs"
echo "you haven't passed obstacle 2"
echo "we have to start it again!"
sleep 10
$0
done
echo "congradulations! you've passed obstacle 2"
echo "let's go on"cat<<EOF2
if you choose ADDING, please enter "a"
if you choose SUBTRACTION, please enter "s"
if you choose MULTIPLICATION, please enter "m"
if you choose DIVISION, please enter "d"
if you want to exit, please enter any other keys
EOF2read action
case $action in
a|A)
echo "working ..."
sleep 2
echo $[$num1+$num2]
echo $?
echo done
;;s|S)
echo "working ..."
sleep 2
echo $[$num1-$num2]
echo done
;;m|M)
echo "working ..."
sleep 2
echo $[$num1*$num2]
echo done
;;d|D)
echo "working ..."
sleep 2
echo $[$num1/$num2]
echo done
;;*)
cat<<EOF3
if you're sure to quit, enter "y"
if you want to view the shell script, enter "v"
(press SPACE to next page, PAGEUP to previous page, PAGEDOWN to next page
ARROWs to more or less lines, "q" to quit "view"
if you want to romove the shell script, enter "r"
if you want to rerun the shell, enter any other keys
EOF3
read quit
if [ $quit == y ]
then
exit
elif [ $quit == v ]
then
less $0
elif [ $quit == r ]
then
rm -f $0
else
clear
cat<<EOF4
START FROM THE SCRATCH !
EOF4
sleep 1
clear
$0
fi
;;esac
[此贴子已经被作者于2004-12-16 12:44:57编辑过]
|
|