Chinaunix首页 | 论坛 | 博客
  • 博客访问: 416547
  • 博文数量: 68
  • 博客积分: 2010
  • 博客等级: 大尉
  • 技术积分: 671
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-11 13:36
文章分类

全部博文(68)

文章存档

2010年(14)

2009年(7)

2008年(47)

我的朋友

分类: LINUX

2010-06-03 15:39:41

今天在cu bbs中看到一个帖子贴了几种用perl实现的进度条显示代码, perl没看过, 不过跟帖中的shell实现方法倒是不错, 以前还真没想过用shell实现, 记下来吧...

#!/bin/sh

b=''
for ((i=0;$i<=100;i+=2))
do
        printf "progress:[%-50s]%d%%\r" $b $i
        sleep 0.1
        b=#$b
done
echo



我再加一个C语言的:

#include <stdio.h>
#include <unistd.h>
#include <string.h>

int main()
{
        char str[128] = "#";
        int i;

        for (i = 0; i < 100; i += 2) {
                fprintf(stdout, "progress:[%-50s]%d%%\r", str, i+2);
                fflush(stdout);
                strcat(str, "#");
                usleep(100000);
        }
        fprintf(
stdout, "\n");
        return 0;
}




---
原帖见:
阅读(6733) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~