I successfully use the python tool tqdm
to display a nice progress bar for e.g. unzipping a large file. However I don't know how to stop that and showing errors from the unzip command if any.
#!/bin/bash
function progressBarFiles() {
local total_files="$1"
if hash tqdm 2>/dev/null; then
tqdm --total $total_files --unit files --desc counting | wc -l >/dev/null
else
cat
fi
}
unzip -o huge.zip | progressBarFiles 1697
Currently I have the case of unzipping in a network folder fails due to file permission changes failing:
counting: 1%|█▉ | 22/1697 [00:00<00:28, 58.36files/s]
chmod (directory attributes) error: Permission denied
chmod (directory attributes) error: Permission denied
chmod (directory attributes) error: Permission denied
counting: 2%|██▎ | 26/1697 [00:00<00:35, 46.64files/s]
chmod (directory attributes) error: Permission denied
I would like to stop the script after the progress bar and print this error output all together instead of at the moment in unzipping (which breaks the progress bar).
PS: Is the idea with cat
to have that progress bar completely optional improvable?