LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 811|回复: 1

???大家有没有发现shell脚本里多重选择结构的问题???

[复制链接]
发表于 2005-5-10 15:30:18 | 显示全部楼层 |阅读模式
我用C shell写了一个测试脚本,内容如附图
1 #!/bin/csh
2 #
3 foreach i (1 2 3 4)
4    echo "when i=$i,enter the test"
5    if($i < 3)then
6       echo "in outer-select then"
7       if($i == 1)then
8          echo "in inner-select1 then"
9       else
10          echo "in inner-select1 else"
11       endif
12    else
13       echo "in outer-select else"
14       if($i == 3)then
15          echo "in inner-select2 then"
16       else
17          echo "in inner-select2 else"
18       endif
19    endif
20 end

运行结果为
Newton% cycletest
when i=1,enter the test
in outer-select then
in inner-select1 then
when i=2,enter the test
in outer-select then
in inner-select1 else
when i=3,enter the test
in inner-select1 else
when i=4,enter the test
in inner-select1 else
Newton%
很显然,当i=3时,应显示in outer-selection else和in inner-select2 then
当i=4时,应显示in outer-selection else和in inner-select2 else
但是,很明显的,系统把第9行的else看做是属于外层选择结构的.
这样就不能用到if-else-endif多重选择,只能用外层if-else-endif包内层switch-case来实现
请问大家是怎么处理这种问题的,用什么来实现多重循环呢?
发表于 2005-5-12 02:47:42 | 显示全部楼层
为什么不用论坛的代码缩进??  看着就晕!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表