Chinaunix首页 | 论坛 | 博客
  • 博客访问: 483321
  • 博文数量: 401
  • 博客积分: 244
  • 博客等级: 入伍新兵
  • 技术积分: 2215
  • 用 户 组: 普通用户
  • 注册时间: 2012-08-04 10:02
文章分类

全部博文(401)

文章存档

2013年(37)

2012年(364)

分类:

2012-09-20 15:18:30

原文地址:Shell 显示一个进度条 作者:iceway_cu

今天在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;
}




---
原帖见:
阅读(219) | 评论(0) | 转发(0) |
0

上一篇:shell后台进度条

下一篇:export -f

给主人留下些什么吧!~~