博客
关于我
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/

    你可能感兴趣的文章
    NMF(非负矩阵分解)
    查看>>
    nmon_x86_64_centos7工具如何使用
    查看>>
    NN&DL4.1 Deep L-layer neural network简介
    查看>>
    NN&DL4.3 Getting your matrix dimensions right
    查看>>
    NN&DL4.7 Parameters vs Hyperparameters
    查看>>
    NN&DL4.8 What does this have to do with the brain?
    查看>>
    nnU-Net 终极指南
    查看>>
    No 'Access-Control-Allow-Origin' header is present on the requested resource.
    查看>>
    NO 157 去掉禅道访问地址中的zentao
    查看>>
    no available service ‘default‘ found, please make sure registry config corre seata
    查看>>
    No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
    查看>>
    no connection could be made because the target machine actively refused it.问题解决
    查看>>
    No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
    查看>>
    No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
    查看>>
    No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
    查看>>
    No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
    查看>>
    No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
    查看>>
    No module named 'crispy_forms'等使用pycharm开发
    查看>>
    No module named cv2
    查看>>
    No module named tensorboard.main在安装tensorboardX的时候遇到的问题
    查看>>