How to optionally show a progress bar, i.e. stop and show error output in a bash script?

Multi tool use
How to optionally show a progress bar, i.e. stop and show error output in a bash script?
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.
tqdm
#!/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?
cat
unzip
Is a temporary file the only solution?
– jan
Jun 18 at 10:04
1 Answer
1
Solved this as stated in the comment with redirecting, but with a clean temporary file that will be deleted 100%, see https://stackoverflow.com/a/51137057/1184842 for more details.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Redirect stderr of the
unzip
to a temp file, cat it to stderr after it's finished.– choroba
Jun 18 at 9:49