Progressbar in bash to visualize the time to wait
In a bash script sometimes you need the user to wait some seconds for a background process to finish.
I usually use for example:
sleep 10
How can I add a kind of progressbar to the script, so the user knows how long to wait?
I installed the command bar
but I don't understand the manual.
bash programming
add a comment |
In a bash script sometimes you need the user to wait some seconds for a background process to finish.
I usually use for example:
sleep 10
How can I add a kind of progressbar to the script, so the user knows how long to wait?
I installed the command bar
but I don't understand the manual.
bash programming
Bash FAQ 44
– jasonwryan
Sep 30 '13 at 5:18
I saw that, but it is only usable for copying files. In that case, I added another answer below
– rubo77
Sep 30 '13 at 5:28
add a comment |
In a bash script sometimes you need the user to wait some seconds for a background process to finish.
I usually use for example:
sleep 10
How can I add a kind of progressbar to the script, so the user knows how long to wait?
I installed the command bar
but I don't understand the manual.
bash programming
In a bash script sometimes you need the user to wait some seconds for a background process to finish.
I usually use for example:
sleep 10
How can I add a kind of progressbar to the script, so the user knows how long to wait?
I installed the command bar
but I don't understand the manual.
bash programming
bash programming
edited Jun 8 '14 at 16:41
rubo77
asked Sep 30 '13 at 4:25
rubo77rubo77
7,4622571133
7,4622571133
Bash FAQ 44
– jasonwryan
Sep 30 '13 at 5:18
I saw that, but it is only usable for copying files. In that case, I added another answer below
– rubo77
Sep 30 '13 at 5:28
add a comment |
Bash FAQ 44
– jasonwryan
Sep 30 '13 at 5:18
I saw that, but it is only usable for copying files. In that case, I added another answer below
– rubo77
Sep 30 '13 at 5:28
Bash FAQ 44
– jasonwryan
Sep 30 '13 at 5:18
Bash FAQ 44
– jasonwryan
Sep 30 '13 at 5:18
I saw that, but it is only usable for copying files. In that case, I added another answer below
– rubo77
Sep 30 '13 at 5:28
I saw that, but it is only usable for copying files. In that case, I added another answer below
– rubo77
Sep 30 '13 at 5:28
add a comment |
4 Answers
4
active
oldest
votes
while true;do echo -n .;sleep 1;done &
sleep 10 # or do something else here
kill $!; trap 'kill $!' SIGTERM
echo done
this will start an infinite while loop that echos a spinner every second, executed in the background.
Instead of the sleep10
command run any command you want.
When that command finishes executing this will kill the last job running in the background (which is the infinite while loop)
source: https://stackoverflow.com/a/16348366/1069083
You can use various while loops instead, e.g. a spinner like this:
while :;do for s in / - \ |; do printf "r$s";sleep 1;done;done
add a comment |
This should be enough to get you started:
#!/bin/bash
for i in {001..100}; do
sleep 1
printf "r $i"
done
Using the r
escape sequence returns the line to the start without a newline. This allows you to update the output without having hundreds of lines of output. By using this base, you could find a way to slowly print out an arrow such as =>25% ==>50% ===>75%
instead of simply printing a number out. You could do this in a very basic way by using if-then logic to print out a specific number of ='s depending on the size of the number.
add a comment |
In case you want to see the progress of a file-copy process, you can simply use
pv source_file > destination_file
or
rsync --progress source_file destination_file
instead of the cp
command
add a comment |
Here's one using cursor movements that will rewrite the line in order to show a countdown:
c=5 # seconds to wait
REWRITE="e[25De[1Ae[K"
echo "Starting..."
while [ $c -gt 0 ]; do
c=$((c-1))
sleep 1
echo -e "${REWRITE}$c"
done
echo -e "${REWRITE}Done."
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f92919%2fprogressbar-in-bash-to-visualize-the-time-to-wait%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
while true;do echo -n .;sleep 1;done &
sleep 10 # or do something else here
kill $!; trap 'kill $!' SIGTERM
echo done
this will start an infinite while loop that echos a spinner every second, executed in the background.
Instead of the sleep10
command run any command you want.
When that command finishes executing this will kill the last job running in the background (which is the infinite while loop)
source: https://stackoverflow.com/a/16348366/1069083
You can use various while loops instead, e.g. a spinner like this:
while :;do for s in / - \ |; do printf "r$s";sleep 1;done;done
add a comment |
while true;do echo -n .;sleep 1;done &
sleep 10 # or do something else here
kill $!; trap 'kill $!' SIGTERM
echo done
this will start an infinite while loop that echos a spinner every second, executed in the background.
Instead of the sleep10
command run any command you want.
When that command finishes executing this will kill the last job running in the background (which is the infinite while loop)
source: https://stackoverflow.com/a/16348366/1069083
You can use various while loops instead, e.g. a spinner like this:
while :;do for s in / - \ |; do printf "r$s";sleep 1;done;done
add a comment |
while true;do echo -n .;sleep 1;done &
sleep 10 # or do something else here
kill $!; trap 'kill $!' SIGTERM
echo done
this will start an infinite while loop that echos a spinner every second, executed in the background.
Instead of the sleep10
command run any command you want.
When that command finishes executing this will kill the last job running in the background (which is the infinite while loop)
source: https://stackoverflow.com/a/16348366/1069083
You can use various while loops instead, e.g. a spinner like this:
while :;do for s in / - \ |; do printf "r$s";sleep 1;done;done
while true;do echo -n .;sleep 1;done &
sleep 10 # or do something else here
kill $!; trap 'kill $!' SIGTERM
echo done
this will start an infinite while loop that echos a spinner every second, executed in the background.
Instead of the sleep10
command run any command you want.
When that command finishes executing this will kill the last job running in the background (which is the infinite while loop)
source: https://stackoverflow.com/a/16348366/1069083
You can use various while loops instead, e.g. a spinner like this:
while :;do for s in / - \ |; do printf "r$s";sleep 1;done;done
edited Dec 30 '18 at 3:47
answered Sep 30 '13 at 5:10
rubo77rubo77
7,4622571133
7,4622571133
add a comment |
add a comment |
This should be enough to get you started:
#!/bin/bash
for i in {001..100}; do
sleep 1
printf "r $i"
done
Using the r
escape sequence returns the line to the start without a newline. This allows you to update the output without having hundreds of lines of output. By using this base, you could find a way to slowly print out an arrow such as =>25% ==>50% ===>75%
instead of simply printing a number out. You could do this in a very basic way by using if-then logic to print out a specific number of ='s depending on the size of the number.
add a comment |
This should be enough to get you started:
#!/bin/bash
for i in {001..100}; do
sleep 1
printf "r $i"
done
Using the r
escape sequence returns the line to the start without a newline. This allows you to update the output without having hundreds of lines of output. By using this base, you could find a way to slowly print out an arrow such as =>25% ==>50% ===>75%
instead of simply printing a number out. You could do this in a very basic way by using if-then logic to print out a specific number of ='s depending on the size of the number.
add a comment |
This should be enough to get you started:
#!/bin/bash
for i in {001..100}; do
sleep 1
printf "r $i"
done
Using the r
escape sequence returns the line to the start without a newline. This allows you to update the output without having hundreds of lines of output. By using this base, you could find a way to slowly print out an arrow such as =>25% ==>50% ===>75%
instead of simply printing a number out. You could do this in a very basic way by using if-then logic to print out a specific number of ='s depending on the size of the number.
This should be enough to get you started:
#!/bin/bash
for i in {001..100}; do
sleep 1
printf "r $i"
done
Using the r
escape sequence returns the line to the start without a newline. This allows you to update the output without having hundreds of lines of output. By using this base, you could find a way to slowly print out an arrow such as =>25% ==>50% ===>75%
instead of simply printing a number out. You could do this in a very basic way by using if-then logic to print out a specific number of ='s depending on the size of the number.
answered Sep 30 '13 at 4:47
bntserbntser
355129
355129
add a comment |
add a comment |
In case you want to see the progress of a file-copy process, you can simply use
pv source_file > destination_file
or
rsync --progress source_file destination_file
instead of the cp
command
add a comment |
In case you want to see the progress of a file-copy process, you can simply use
pv source_file > destination_file
or
rsync --progress source_file destination_file
instead of the cp
command
add a comment |
In case you want to see the progress of a file-copy process, you can simply use
pv source_file > destination_file
or
rsync --progress source_file destination_file
instead of the cp
command
In case you want to see the progress of a file-copy process, you can simply use
pv source_file > destination_file
or
rsync --progress source_file destination_file
instead of the cp
command
answered Sep 30 '13 at 5:23
rubo77rubo77
7,4622571133
7,4622571133
add a comment |
add a comment |
Here's one using cursor movements that will rewrite the line in order to show a countdown:
c=5 # seconds to wait
REWRITE="e[25De[1Ae[K"
echo "Starting..."
while [ $c -gt 0 ]; do
c=$((c-1))
sleep 1
echo -e "${REWRITE}$c"
done
echo -e "${REWRITE}Done."
add a comment |
Here's one using cursor movements that will rewrite the line in order to show a countdown:
c=5 # seconds to wait
REWRITE="e[25De[1Ae[K"
echo "Starting..."
while [ $c -gt 0 ]; do
c=$((c-1))
sleep 1
echo -e "${REWRITE}$c"
done
echo -e "${REWRITE}Done."
add a comment |
Here's one using cursor movements that will rewrite the line in order to show a countdown:
c=5 # seconds to wait
REWRITE="e[25De[1Ae[K"
echo "Starting..."
while [ $c -gt 0 ]; do
c=$((c-1))
sleep 1
echo -e "${REWRITE}$c"
done
echo -e "${REWRITE}Done."
Here's one using cursor movements that will rewrite the line in order to show a countdown:
c=5 # seconds to wait
REWRITE="e[25De[1Ae[K"
echo "Starting..."
while [ $c -gt 0 ]; do
c=$((c-1))
sleep 1
echo -e "${REWRITE}$c"
done
echo -e "${REWRITE}Done."
edited Sep 30 '13 at 10:26
rubo77
7,4622571133
7,4622571133
answered Sep 30 '13 at 8:03
SuprSupr
1414
1414
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f92919%2fprogressbar-in-bash-to-visualize-the-time-to-wait%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Bash FAQ 44
– jasonwryan
Sep 30 '13 at 5:18
I saw that, but it is only usable for copying files. In that case, I added another answer below
– rubo77
Sep 30 '13 at 5:28