首页 > 系统相关 > shell脚本显示多层进度条

shell脚本显示多层进度条

时间:2022-08-24 10:34:27浏览次数:43  
标签:脚本 shell 进度条 100% 多层 ###########################################################

一句话,欢迎交流

 

先看效果:

 
[####################################################################################################][100%]
[####################################################################################################][100%]
[####################################################################################################][100%]
 
安装完成

 

再看代码:

#!/bin/bash

function process_bar() {
        # 该函数有2参数, $1是控制在第几行输出  $2是进度百分比
        line=$1
        percent=$2
        
        str=""
        for ((k = 1; k <= $percent; k++)); 
        do 
          str+='#' 
        done
        
        #tput 控制光标位置,移动到第n行第0列
        tput cup $line 0
        
        #输出格式化的字符串
        printf "[%-100s][%d%%]\r" $str $percent 

}

function install() {

      tput init
      tput clear


      #设置画布大小  5行
      for ((line = 1; line <= 5; line++));
      do
         printf "\n"
      done

       
      #显示进度, 这里可以把 $i 替换成自定义的百分比
      for ((i = 1; i <= 100; i++));
      do
         sleep 0.01
         process_bar 1 "$i"
         process_bar 2 "$i"
         process_bar 3 "$i"
      done

      tput cup 5 0
      printf "安装完成\n"
}


#程序入口
install

 

标签:脚本,shell,进度条,100%,多层,###########################################################
From: https://www.cnblogs.com/do-e/p/16618938.html

相关文章

  • PowerShell教程 - 文件系统管理(File System Management)
    更新记录转载请注明出处。2022年8月24日发布。2022年8月18日从笔记迁移到博客。文件系统管理(FileSystemManagement)文件类型说明与Linux不同,Windows下只有3种文......
  • PowerShell教程 - 系统事件管理(System Event Management)
    更新记录转载请注明出处。2022年8月24日发布。2022年8月18日从笔记迁移到博客。系统事件管理(SystemEventManagement)显示事件管理器Show-EventLog获得事件条......
  • PowerShell教程 - 磁盘与硬件管理(Disk & Hardware Management)
    更新记录转载请注明出处。2022年8月24日发布。2022年8月18日从笔记迁移到博客。磁盘与硬件管理(Disk&HardwareManagement)添加磁盘(挂载)New-PSDrive查看已添加......
  • Linux-shell笔记1
    一次执行很多命令,可以用;分割每个命令,依次运行所有命令。但是不是进程列表,要用()包围命令才是进程列表。它们有什么差别呢?进程列表是启动了一个子SHELL来执行的。用echo$BA......
  • windows powershell安装oh-my-posh提示
    官网教程:https://ohmyposh.dev/docs/installation/windows安装使用winget/scoop/手动安装oh-my-poshscoopinstallhttps://github.com/JanDeDobbeleer/oh-my-posh/r......
  • PowerShell教程 - 服务管理(Service Management)
    更新记录转载请注明出处。2022年8月23日发布。2022年8月18日从笔记迁移到博客。服务管理(ServiceManagement)获得服务Get-Service实例:Get-Service-NameM*......
  • PowerShell教程 - 网络管理(Network Management)
    更新记录转载请注明出处。2022年8月23日发布。2022年8月18日从笔记迁移到博客。网络管理(NetworkManagement)获得网卡信息Get-NetAdapter测试网络连通性实例:......
  • xshell 保持活跃状态不关闭
    xshell保持活跃状态不关闭1.1点击文件》属性2.1修改回车时间保持3600秒活跃,每360秒自动输入一次回车......
  • Shell | Shell 编程基础(三)
    Shell|Shell编程基础(三)一、编程基础解释器:Shell脚本第一行指定解释器必须写#!/bin/bash,如果没有会默认使用#!/bin/sh作为解释程序注释:Shell注释,单行#,多行<......
  • Linux shell for语句的使用
    [22:26:42root@libin3libin]#catlibin6rhcsarhcerhcahcialibin1hciplibin2hcielibin3[22:26:52root@libin3libin]#foriin`catlibin6`;doping-c......