LinuxSir.cn,穿越时空的Linuxsir!

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

各位帮我检查一下什么问题

[复制链接]
发表于 2006-10-10 17:33:43 | 显示全部楼层 |阅读模式

  1. #!/bin/bash
  2. cp file1 file2 &
  3. SSZIE=284712239
  4. bf=0
  5. while [[ $bf -lt 101 ]];do
  6.         if [[ $bf -lt 100 ]];then
  7.                 jd="$bf%%"
  8.         else
  9.                 jd="done"
  10.         fi
  11.         printf "\rtesting...       $jd"
  12.         if [ -f test ];then
  13.                 TSIZE=`ls -l file2 |awk '{print $5}'`
  14.                 bf=`perl -e "print $TSIZE/$SSIZE*100"|awk -F"." '{print $1}'`
  15.         fi
  16. done
  17. printf "\n"
复制代码

ssize的量是定的.就免了去ls-l了
执行结果如此
testing...       0%Illegal division by zero at -e line 1.
testing...       %Illegal division by zero at -e line 1.
testing...       %Illegal division by zero at -e line 1.
testing...       %Illegal division by zero at -e line 1.
testing...       %Illegal division by zero at -e line 1.
testing...       %Illegal division by zero at -e line 1.
testing...       %Illegal division by zero at -e line 1.
testing...       %Illegal division by zero at -e line 1.
testing...       %Illegal division by zero at -e line 1.
testing...       %Illegal division by zero at -e line 1.
testing...       %Illegal division by zero at -e line 1.
不知哪里邮问题
 楼主| 发表于 2006-10-10 17:35:35 | 显示全部楼层
谢谢各位了.帮帮忙
回复 支持 反对

使用道具 举报

发表于 2006-10-10 17:41:09 | 显示全部楼层
是不是这个地方:jd="$bf%%"多了个%,我是瞎猜,呵呵。
回复 支持 反对

使用道具 举报

发表于 2006-10-10 17:53:33 | 显示全部楼层
复制文件的进度条?

问题出在那个Perl命令上,0不可为除数,Perl不能直接访问Shell变量?
回复 支持 反对

使用道具 举报

发表于 2006-10-10 23:36:04 | 显示全部楼层
Line 3 SSIZE not SSZIE


#!/bin/bash
cp file1 file2 &
SSIZE=523625
bf=0
while [[ $bf -lt 100 ]];do
        if [[ $bf -lt 100 ]];then
                jd="$bf%%"
        else
                jd="done"
        fi
        printf "\rtesting...       $jd"
        if [ -f file2 ];then
                TSIZE=`ls -l file2 |awk '{print $5}'`
                bf=`perl -e "print $TSIZE/$SSIZE*100"|awk -F"." '{print $1}'`
        fi
done
printf "\n"
回复 支持 反对

使用道具 举报

发表于 2006-10-11 01:25:49 | 显示全部楼层
Post by kevinliu
Line 3 SSIZE not SSZIE
Can't believe that Yuri made this kind of mistake, haha.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-10-11 09:05:14 | 显示全部楼层
Post by biinn
Can't believe that Yuri made this kind of mistake, haha.

不许说洋文,我看不懂
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-10-11 09:06:49 | 显示全部楼层
Post by troll
复制文件的进度条?

问题出在那个Perl命令上,0不可为除数,Perl不能直接访问Shell变量?

正是,0可以作为除数,per也l可以访问shell变量的吧.我这里试了一下可以啊.

  1. #!/bin/bash
  2. SSIZE=284712759
  3. TSIZE=`ls -l /root/test |awk '{print $5}'`
  4. bf=`perl -e "print 0/$SSIZE*100"|awk -F"." '{print $1}'`
  5. echo $bf
复制代码

执行这个是可以的.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-10-11 09:12:54 | 显示全部楼层
Post by luke_guo
是不是这个地方:jd="$bf%%"多了个%,我是瞎猜,呵呵。

printf的%当\使的.(看MAN看的,E文不好,不太确定,但实践了一下)
回复 支持 反对

使用道具 举报

发表于 2006-10-11 09:31:36 | 显示全部楼层
Post by kevinliu
Line 3 SSIZE not SSZIE

学习不认真,仔细看kevin的回复:你的第三行有个笔误。
回复 支持 反对

使用道具 举报

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

本版积分规则

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