![]() |
中国DOS联盟-- 联合DOS 推动DOS 发展DOS --联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum |
| 游客 | 登录 | 注册 | 会员 | 搜索 | 中国DOS联盟 |
|
中国DOS联盟论坛 现在时间是 2026-08-26 10:11 |
共 47,812 主题排行 / 349,910 发帖 / 今日 0 篇 / 48,264 会员排行 |
| 其它操作系统综合讨论区 » 刚玩了玩控制语句,与大家共勉 |
| 可打印版本 766 / 0 |
| 第1楼 GOTOmsdos | 发表于 2004-12-15 00:00 |
| 铂金会员 发帖 1,827 积分 5,154 | |
|
刚玩了玩控制语句,与大家共勉 刚装上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 |
|
|
[ 联系联盟系统管理团队 -
中国DOS联盟 -
标准版 ] Sponsored by ifanr Inc | © 2001–2023 |