中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-06-13 23:25
中国DOS联盟论坛 » 其它操作系统综合讨论区 » 刚玩了玩控制语句,与大家共勉
楼 主 刚玩了玩控制语句,与大家共勉 发表于 2004-12-15 00:00 ·  中国 广东 广州 教育网
铂金会员
★★★★
C++启程者
积分 5,154
发帖 1,827
注册 2003-07-18 00:00
UID 7105
性别 男
状态 离线
刚装上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
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
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
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 $
echo $?
echo done
;;s|S)
echo "working ..."
sleep 2
echo $
echo done
;;m|M)
echo "working ..."
sleep 2
echo $
echo done
;;d|D)
echo "working ..."
sleep 2
echo $
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
then
exit
elif
then
less $0
elif
then
rm -f $0
else
clear
cat<<EOF4

START FROM THE SCRATCH !
EOF4
sleep 1
clear
$0
fi
;;esac




论坛跳转: