免费注册 查看新帖 |

Chinaunix

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

为啥for循环不执行 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-08-23 00:52 |只看该作者 |倒序浏览
#!/bin/bash
  2 numargs=$#
  3 filelist=
  4 copylist=
  5
  6 while [ "$#" -gt 1 ]
  7 do
  8         filelist="$filelist $1"
  9         shift
10 done
11 to="$1"
12 if [ "$numargs" -lt 2 -o "$numargs" -gt 2 -a ! -d "$to" ]
13 then
14         echo "Usage: test file1 file2"
15         echo "  test file(s) dir"
16         exit 1
17 fi
18
19 for from in #filelist
20 do
21         if [ -d "$to" ]
22         then
23                 tofile="$to/$(basename $from)"
24         else
25                 tofile="$to"
26         fi
27         if [ -e "$tofile" ]
28         then
29                 echo "$tofile already exists; overwirte (yes/no)? "
30                 read answer
31                 if [ "$answer" != yes ]
32                 then
33                         echo "copy not performed"
34                         continue
35                 else
36                         copylist="$copylist $from"
37                 fi
38         else
39                 copylist="$copylist $from"
40         fi
41 done
42
43 if [ -n "$copylist" ]
44 then
45         cp $copylist $to
46 fi


[root@station1 ~]# sh -x ./test f1 f2 b
+ numargs=3
+ filelist=
+ copylist=
+ '[' 3 -gt 1 ']'
+ filelist=' f1'
+ shift
+ '[' 2 -gt 1 ']'
+ filelist=' f1 f2'
+ shift
+ '[' 1 -gt 1 ']'
+ to=b
+ '[' 3 -lt 2 -o 3 -gt 2 -a '!' -d b ']'
+ '[' -n '' ']'

[ 本帖最后由 zhaobin81 于 2009-8-23 00:56 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2009-08-23 08:23 |只看该作者
#filelist  ???
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP