Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 打印Apt的进度条_Bash - Fatal编程技术网

Bash 打印Apt的进度条

Bash 打印Apt的进度条,bash,Bash,我发现了一种用于apt和apt-get的方法,为了编写脚本,我尝试只打印进度条。我在grep(grep“Progress:)或tail(tail-1)方面没有取得任何成功。这可能吗?我的方向正确吗?进度条可能不会打印到标准输出 尝试通过2>&1 | grep Progress:移动它,如果我知道您只是试图在apt或apt get代码中查找进度条,以便您以后可以使用它,则无法保证它的名称为Progress:,或者包含进度:的提示甚至在您正在搜索的脚本中。它可能来自另一个文件 您可以尝试在编辑器(如

我发现了一种用于apt和apt-get的方法,为了编写脚本,我尝试只打印进度条。我在grep(
grep“Progress:
)或tail(
tail-1
)方面没有取得任何成功。这可能吗?我的方向正确吗?

进度条可能不会打印到标准输出


尝试通过
2>&1 | grep Progress:

移动它,如果我知道您只是试图在apt或apt get代码中查找进度条,以便您以后可以使用它,则无法保证它的名称为
Progress:
,或者包含
进度:
的提示甚至在您正在搜索的脚本中。它可能来自另一个文件

您可以尝试在编辑器(如
vim
kwrite
jot
等)中打开脚本,在脚本中查找仪表的调用位置并从那里开始。不知道它是否会在
刻度
仪表
百分比
等以下

在找不到任何东西的情况下,你总是可以用一些简单的东西。网络上有许多可用的工具。例如:

#!/bin/bash

## string of characters for meter (60 - good for 120 char width)
str='▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒'

tput civis                  # make cursor invisible

for i in `seq 1 100`; do    # for 1 to 100, save cursor, restore, output, restore
    printf "\033[s\033[u Progress: %s %3d %% \033[u" "${str:0:$(((i+1)/2))}" "$i"
    sleep 0.1               # small delay
done

printf "\033[K"             # clear to end-of-line

tput cnorm                  # restore cursor to normal

exit 0