中国DOS联盟论坛

中国DOS联盟

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

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

游客:  注册 | 登录 | 命令行 | 会员 | 搜索 | 上传 | 帮助 »
中国DOS联盟论坛 » 其它操作系统综合讨论区 » 刚玩了玩控制语句,与大家共勉
作者:
标题: 刚玩了玩控制语句,与大家共勉 上一主题 | 下一主题
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编辑过]




2004-12-15 00:00
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复

请注意:您目前尚未注册或登录,请您注册登录以使用论坛的各项功能,例如发表和回复帖子等。


可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题



论坛跳转: