Skip to content

Instantly share code, notes, and snippets.

@maurostorch
Last active February 16, 2024 10:59
Show Gist options
  • Save maurostorch/cc12739c8260e42b1f0802bc8cbccdfc to your computer and use it in GitHub Desktop.
Save maurostorch/cc12739c8260e42b1f0802bc8cbccdfc to your computer and use it in GitHub Desktop.
progressbar in bash for anything
#!/bin/bash
# could be placed in a single line
A=$1; # change to something with a number, first script's arg
B=$((A*40/$2)); # calculates the portion in a progress bar of 40 # where $2 is the total as 2nd script's arg
C=$((40-B)); # left
B=$(printf "%${B}s");
C=$(printf "%${C}s");
printf "\r[${B// /#}${C// /-}] $A%%\n" $A;
@maurostorch
Copy link
Author

the result:
[########################----------------] 61%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment