博客
关于我
linux shell脚本模拟百分比进度显示
阅读量:586 次
发布时间:2019-03-11

本文共 714 字,大约阅读时间需要 2 分钟。

Bash脚本进程管理示例

以下是基于Bash脚本实现的一个简单进程管理示例,用于展示进程数的动态变化效果。

#!/bin/bashfunction delayTime {    time=$1    sleep $time}function printProcessNum {    num=$1    echo -e -n "\033[1;32m\b\b\b\b$num%\033[1;0m"}function process {    delay=$1    # 默认延迟0.1秒    if [ $# -gt 1 ]; then        delay=$2    fi    for i in $(seq 0 100); do        printProcessNum $i        delayTime $delay    done    echo ""}# 执行脚本时可传入延迟参数,默认为0.1秒process $1

功能说明

  • delayTime函数:用于接收时间参数并执行睡眠操作。
  • printProcessNum函数:用于输出当前进程数量,带有颜色显示效果。
  • process函数:主函数,接收延迟参数并执行循环,动态显示进程数。
  • 执行效果展示

    当脚本运行时,会在终端输出一系列带有颜色代码的进程数,从0递增到100,间隔为指定的延迟时间。每个进程数前面会有特定的颜色装饰,方便观察进程执行情况。

    使用方法

  • 将脚本保存为.bash脚本文件
  • 使用chmod +x赋予执行权限
  • 根据需要传入延迟参数
  • 执行脚本即可观察效果
  • 这个脚本可以根据实际需求进行修改和扩展,适用于需要展示进程状态或执行延迟操作的场景。

    转载地址:http://uyktz.baihongyu.com/

    你可能感兴趣的文章
    POJ 2892 Tunnel Warfare(树状数组+二分)
    查看>>
    poj 2965 The Pilots Brothers' refrigerator-1
    查看>>
    poj 3026( Borg Maze BFS + Prim)
    查看>>
    POJ 3041 - 最大二分匹配
    查看>>
    POJ 3041 Asteroids(二分匹配模板题)
    查看>>
    Qt笔记——标准文件对话框QFileDialog
    查看>>
    poj 3083 Children of the Candy Corn
    查看>>
    POJ 3083 Children of the Candy Corn 解题报告
    查看>>
    POJ 3253 Fence Repair C++ STL multiset 可解 (同51nod 1117 聪明的木匠)
    查看>>
    Qt笔记——控件总结
    查看>>
    poj 3262 Protecting the Flowers 贪心
    查看>>
    poj 3264(简单线段树)
    查看>>
    Qt笔记——布局管理三件套分割窗口、停靠窗口和堆栈窗口
    查看>>
    poj 3277 线段树
    查看>>
    POJ 3349 Snowflake Snow Snowflakes
    查看>>
    POJ 3411 DFS
    查看>>
    poj 3422 Kaka's Matrix Travels (费用流 + 拆点)
    查看>>
    Qt笔记——官方文档全局定义(二)Functions函数
    查看>>
    POJ 3468 A Simple Problem with Integers
    查看>>
    poj 3468 A Simple Problem with Integers 降维线段树
    查看>>