免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 17279 | 回复: 5
打印 上一主题 下一主题

shell编程中如何让while循环永远执行 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-09-25 16:19 |只看该作者 |倒序浏览
rt
是bash
我想让while循环一直执行,也就是条件永真,可以用空表示吗,如何表示?
谢谢!

论坛徽章:
0
2 [报告]
发表于 2008-09-25 16:27 |只看该作者
while :
                   !!!!!!!!!!!!!!!!!!

论坛徽章:
0
3 [报告]
发表于 2008-09-25 16:54 |只看该作者
原帖由 timdcn 于 2008-9-25 16:27 发表
while :
                   !!!!!!!!!!!!!!!!!!

谢谢ms不行阿。我的代码是这样的
#!/bin/sh
#Program:
#        The program will show a menu in the screen and do different things according to user's choice.
#History:
#2008/9/25                                Sun                                        0.1
mydate=`date +%d/%m/%Y`
local_host=`hostname -s`
user=`whoami`
# begin loop forever
while  :
do
        tput clear
        cat <<mayday
        -------------------------------------------------------------------------------------------
        User: $user                                Host: $local_host                        Datemydate
        -------------------------------------------------------------------------------------------
                        1 : List files in the current directory
                        2 : Use the vi editor
                        3 : See who is on the system
                        H : Help screen
                        Q : Exit Menu

        --------------------------------------------------------------------------------------------
        mayday
        echo -e -n " \tYour choice [1,2,3,H,Q] >"
        read choice
        case $choice in
        1) ls
           ;;
        2) vi
           ;;
        3) who
           ;;
        H|h)
        cat <<mayday
        This is the help  screen,nothin here yet to help you!
        mayday
           ;;
        Q|q) exit 0
           ;;
        *) echo -e "\tunknown user response"
           ;;
        esac
        echo -e -n "\tHit the return key to continue"
        read dummy
done
提示:line 47:syntax error :unexpected end of file

论坛徽章:
0
4 [报告]
发表于 2008-09-25 17:29 |只看该作者
while [ 0 ]

论坛徽章:
0
5 [报告]
发表于 2008-09-25 18:42 |只看该作者
while (true)

论坛徽章:
3
2015年迎新春徽章
日期:2015-03-04 09:56:11数据库技术版块每日发帖之星
日期:2016-08-03 06:20:00数据库技术版块每日发帖之星
日期:2016-08-04 06:20:00
6 [报告]
发表于 2008-09-25 20:57 |只看该作者
while :;do :;done
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP