Chinaunix首页 | 论坛 | 博客
  • 博客访问: 208683
  • 博文数量: 69
  • 博客积分: 153
  • 博客等级: 入伍新兵
  • 技术积分: 595
  • 用 户 组: 普通用户
  • 注册时间: 2011-07-27 09:27
文章分类

全部博文(69)

文章存档

2012年(4)

2010年(13)

2009年(7)

2008年(45)

我的朋友

分类: 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;
}




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