Display Spinner while waiting for some process to finish
How can I show spinner till command line finish it is job? In other words, If I am running a script and I want to show spinner while this script is running and the spinner disappears when the script finish it is job.
Bellow is a common spinner code:
i=1
sp="/-|"
echo -n ' '
while true
do
printf "b${sp:i++%${#sp}:1}"
done
How can I link the previous spinner code to a command to let it show spinner while the command is running and the spinner disappears when the command finish it is job? If I include the command inside the loop it will loop with the spinner so what is the solution in this case?
bash
add a comment |
How can I show spinner till command line finish it is job? In other words, If I am running a script and I want to show spinner while this script is running and the spinner disappears when the script finish it is job.
Bellow is a common spinner code:
i=1
sp="/-|"
echo -n ' '
while true
do
printf "b${sp:i++%${#sp}:1}"
done
How can I link the previous spinner code to a command to let it show spinner while the command is running and the spinner disappears when the command finish it is job? If I include the command inside the loop it will loop with the spinner so what is the solution in this case?
bash
add a comment |
How can I show spinner till command line finish it is job? In other words, If I am running a script and I want to show spinner while this script is running and the spinner disappears when the script finish it is job.
Bellow is a common spinner code:
i=1
sp="/-|"
echo -n ' '
while true
do
printf "b${sp:i++%${#sp}:1}"
done
How can I link the previous spinner code to a command to let it show spinner while the command is running and the spinner disappears when the command finish it is job? If I include the command inside the loop it will loop with the spinner so what is the solution in this case?
bash
How can I show spinner till command line finish it is job? In other words, If I am running a script and I want to show spinner while this script is running and the spinner disappears when the script finish it is job.
Bellow is a common spinner code:
i=1
sp="/-|"
echo -n ' '
while true
do
printf "b${sp:i++%${#sp}:1}"
done
How can I link the previous spinner code to a command to let it show spinner while the command is running and the spinner disappears when the command finish it is job? If I include the command inside the loop it will loop with the spinner so what is the solution in this case?
bash
bash
asked Aug 24 '15 at 17:03
user88036
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Have your while loop watch for your real command to exit. I'll assume a Linux environment that has /proc entries for each PID, but you could slice it other ways:
#!/bin/bash
# your real command here, instead of sleep
sleep 7 &
PID=$!
i=1
sp="/-|"
echo -n ' '
while [ -d /proc/$PID ]
do
printf "b${sp:i++%${#sp}:1}"
done
3
This is a busy loop that will eat up cpu resources. I'd suggest having a delay of some kind in your while loop.
– ACase
Jul 20 '16 at 14:36
add a comment |
This shell script should do what you're looking for:
#!/usr/bin/env bash
show_spinner()
{
local -r pid="${1}"
local -r delay='0.75'
local spinstr='|/-'
local temp
while ps a | awk '{print $1}' | grep -q "${pid}"; do
temp="${spinstr#?}"
printf " [%c] " "${spinstr}"
spinstr=${temp}${spinstr%"${temp}"}
sleep "${delay}"
printf "bbbbbb"
done
printf " bbbb"
}
("$@") &
show_spinner "$!"
You can invoke it like this to display a spinner while the command sleep 10 is running:
$ spinner sleep 10
See also stackoverflow.com/a/20369590/2908724
– bishop
Oct 21 '16 at 17:28
add a comment |
Some creativity while waiting.
#!/bin/bash
# b.nelissen
# spinner demo code
# stepsize is the number of characters per animation step
# frames is the frame-art
# stepsize=1; frames='⌜⌝⌟⌞'
# stepsize=1; frames='🕐🕜🕑🕝🕒🕞🕓🕟🕔🕠🕕🕡🕖🕢🕗🕣🕘🕤🕙🕥🕚🕦🕛🕧'
# stepsize=1; frames='⛔️ '
stepsize=12; frames=' 🎾 | 🎾 | | 🎾 | | 🎾 | | 🎾 | | 🎾 | | 🎾 | | 🎾 / | 🎾/ | 🎾 | | 🎾 | | 🎾 | | 🎾 | | 🎾 | '
# the loop
while true; do
s=$(( (s+$stepsize) %${#frames} ));
printf "r${frames:$s:$stepsize}"
sleep 0.2
done
Animated gif:
Good ideas, but since your post is not an answer in itself I think you should either elaborate until it's one, or edit a previous answer and put your code in that.
– PetaspeedBeaver
5 hours ago
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%2f225179%2fdisplay-spinner-while-waiting-for-some-process-to-finish%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Have your while loop watch for your real command to exit. I'll assume a Linux environment that has /proc entries for each PID, but you could slice it other ways:
#!/bin/bash
# your real command here, instead of sleep
sleep 7 &
PID=$!
i=1
sp="/-|"
echo -n ' '
while [ -d /proc/$PID ]
do
printf "b${sp:i++%${#sp}:1}"
done
3
This is a busy loop that will eat up cpu resources. I'd suggest having a delay of some kind in your while loop.
– ACase
Jul 20 '16 at 14:36
add a comment |
Have your while loop watch for your real command to exit. I'll assume a Linux environment that has /proc entries for each PID, but you could slice it other ways:
#!/bin/bash
# your real command here, instead of sleep
sleep 7 &
PID=$!
i=1
sp="/-|"
echo -n ' '
while [ -d /proc/$PID ]
do
printf "b${sp:i++%${#sp}:1}"
done
3
This is a busy loop that will eat up cpu resources. I'd suggest having a delay of some kind in your while loop.
– ACase
Jul 20 '16 at 14:36
add a comment |
Have your while loop watch for your real command to exit. I'll assume a Linux environment that has /proc entries for each PID, but you could slice it other ways:
#!/bin/bash
# your real command here, instead of sleep
sleep 7 &
PID=$!
i=1
sp="/-|"
echo -n ' '
while [ -d /proc/$PID ]
do
printf "b${sp:i++%${#sp}:1}"
done
Have your while loop watch for your real command to exit. I'll assume a Linux environment that has /proc entries for each PID, but you could slice it other ways:
#!/bin/bash
# your real command here, instead of sleep
sleep 7 &
PID=$!
i=1
sp="/-|"
echo -n ' '
while [ -d /proc/$PID ]
do
printf "b${sp:i++%${#sp}:1}"
done
answered Aug 24 '15 at 17:22
Jeff SchallerJeff Schaller
39.7k1054126
39.7k1054126
3
This is a busy loop that will eat up cpu resources. I'd suggest having a delay of some kind in your while loop.
– ACase
Jul 20 '16 at 14:36
add a comment |
3
This is a busy loop that will eat up cpu resources. I'd suggest having a delay of some kind in your while loop.
– ACase
Jul 20 '16 at 14:36
3
3
This is a busy loop that will eat up cpu resources. I'd suggest having a delay of some kind in your while loop.
– ACase
Jul 20 '16 at 14:36
This is a busy loop that will eat up cpu resources. I'd suggest having a delay of some kind in your while loop.
– ACase
Jul 20 '16 at 14:36
add a comment |
This shell script should do what you're looking for:
#!/usr/bin/env bash
show_spinner()
{
local -r pid="${1}"
local -r delay='0.75'
local spinstr='|/-'
local temp
while ps a | awk '{print $1}' | grep -q "${pid}"; do
temp="${spinstr#?}"
printf " [%c] " "${spinstr}"
spinstr=${temp}${spinstr%"${temp}"}
sleep "${delay}"
printf "bbbbbb"
done
printf " bbbb"
}
("$@") &
show_spinner "$!"
You can invoke it like this to display a spinner while the command sleep 10 is running:
$ spinner sleep 10
See also stackoverflow.com/a/20369590/2908724
– bishop
Oct 21 '16 at 17:28
add a comment |
This shell script should do what you're looking for:
#!/usr/bin/env bash
show_spinner()
{
local -r pid="${1}"
local -r delay='0.75'
local spinstr='|/-'
local temp
while ps a | awk '{print $1}' | grep -q "${pid}"; do
temp="${spinstr#?}"
printf " [%c] " "${spinstr}"
spinstr=${temp}${spinstr%"${temp}"}
sleep "${delay}"
printf "bbbbbb"
done
printf " bbbb"
}
("$@") &
show_spinner "$!"
You can invoke it like this to display a spinner while the command sleep 10 is running:
$ spinner sleep 10
See also stackoverflow.com/a/20369590/2908724
– bishop
Oct 21 '16 at 17:28
add a comment |
This shell script should do what you're looking for:
#!/usr/bin/env bash
show_spinner()
{
local -r pid="${1}"
local -r delay='0.75'
local spinstr='|/-'
local temp
while ps a | awk '{print $1}' | grep -q "${pid}"; do
temp="${spinstr#?}"
printf " [%c] " "${spinstr}"
spinstr=${temp}${spinstr%"${temp}"}
sleep "${delay}"
printf "bbbbbb"
done
printf " bbbb"
}
("$@") &
show_spinner "$!"
You can invoke it like this to display a spinner while the command sleep 10 is running:
$ spinner sleep 10
This shell script should do what you're looking for:
#!/usr/bin/env bash
show_spinner()
{
local -r pid="${1}"
local -r delay='0.75'
local spinstr='|/-'
local temp
while ps a | awk '{print $1}' | grep -q "${pid}"; do
temp="${spinstr#?}"
printf " [%c] " "${spinstr}"
spinstr=${temp}${spinstr%"${temp}"}
sleep "${delay}"
printf "bbbbbb"
done
printf " bbbb"
}
("$@") &
show_spinner "$!"
You can invoke it like this to display a spinner while the command sleep 10 is running:
$ spinner sleep 10
answered Apr 14 '16 at 21:03
jsearsjsears
17114
17114
See also stackoverflow.com/a/20369590/2908724
– bishop
Oct 21 '16 at 17:28
add a comment |
See also stackoverflow.com/a/20369590/2908724
– bishop
Oct 21 '16 at 17:28
See also stackoverflow.com/a/20369590/2908724
– bishop
Oct 21 '16 at 17:28
See also stackoverflow.com/a/20369590/2908724
– bishop
Oct 21 '16 at 17:28
add a comment |
Some creativity while waiting.
#!/bin/bash
# b.nelissen
# spinner demo code
# stepsize is the number of characters per animation step
# frames is the frame-art
# stepsize=1; frames='⌜⌝⌟⌞'
# stepsize=1; frames='🕐🕜🕑🕝🕒🕞🕓🕟🕔🕠🕕🕡🕖🕢🕗🕣🕘🕤🕙🕥🕚🕦🕛🕧'
# stepsize=1; frames='⛔️ '
stepsize=12; frames=' 🎾 | 🎾 | | 🎾 | | 🎾 | | 🎾 | | 🎾 | | 🎾 | | 🎾 / | 🎾/ | 🎾 | | 🎾 | | 🎾 | | 🎾 | | 🎾 | '
# the loop
while true; do
s=$(( (s+$stepsize) %${#frames} ));
printf "r${frames:$s:$stepsize}"
sleep 0.2
done
Animated gif:
Good ideas, but since your post is not an answer in itself I think you should either elaborate until it's one, or edit a previous answer and put your code in that.
– PetaspeedBeaver
5 hours ago
add a comment |
Some creativity while waiting.
#!/bin/bash
# b.nelissen
# spinner demo code
# stepsize is the number of characters per animation step
# frames is the frame-art
# stepsize=1; frames='⌜⌝⌟⌞'
# stepsize=1; frames='🕐🕜🕑🕝🕒🕞🕓🕟🕔🕠🕕🕡🕖🕢🕗🕣🕘🕤🕙🕥🕚🕦🕛🕧'
# stepsize=1; frames='⛔️ '
stepsize=12; frames=' 🎾 | 🎾 | | 🎾 | | 🎾 | | 🎾 | | 🎾 | | 🎾 | | 🎾 / | 🎾/ | 🎾 | | 🎾 | | 🎾 | | 🎾 | | 🎾 | '
# the loop
while true; do
s=$(( (s+$stepsize) %${#frames} ));
printf "r${frames:$s:$stepsize}"
sleep 0.2
done
Animated gif:
Good ideas, but since your post is not an answer in itself I think you should either elaborate until it's one, or edit a previous answer and put your code in that.
– PetaspeedBeaver
5 hours ago
add a comment |
Some creativity while waiting.
#!/bin/bash
# b.nelissen
# spinner demo code
# stepsize is the number of characters per animation step
# frames is the frame-art
# stepsize=1; frames='⌜⌝⌟⌞'
# stepsize=1; frames='🕐🕜🕑🕝🕒🕞🕓🕟🕔🕠🕕🕡🕖🕢🕗🕣🕘🕤🕙🕥🕚🕦🕛🕧'
# stepsize=1; frames='⛔️ '
stepsize=12; frames=' 🎾 | 🎾 | | 🎾 | | 🎾 | | 🎾 | | 🎾 | | 🎾 | | 🎾 / | 🎾/ | 🎾 | | 🎾 | | 🎾 | | 🎾 | | 🎾 | '
# the loop
while true; do
s=$(( (s+$stepsize) %${#frames} ));
printf "r${frames:$s:$stepsize}"
sleep 0.2
done
Animated gif:
Some creativity while waiting.
#!/bin/bash
# b.nelissen
# spinner demo code
# stepsize is the number of characters per animation step
# frames is the frame-art
# stepsize=1; frames='⌜⌝⌟⌞'
# stepsize=1; frames='🕐🕜🕑🕝🕒🕞🕓🕟🕔🕠🕕🕡🕖🕢🕗🕣🕘🕤🕙🕥🕚🕦🕛🕧'
# stepsize=1; frames='⛔️ '
stepsize=12; frames=' 🎾 | 🎾 | | 🎾 | | 🎾 | | 🎾 | | 🎾 | | 🎾 | | 🎾 / | 🎾/ | 🎾 | | 🎾 | | 🎾 | | 🎾 | | 🎾 | '
# the loop
while true; do
s=$(( (s+$stepsize) %${#frames} ));
printf "r${frames:$s:$stepsize}"
sleep 0.2
done
Animated gif:
edited 6 hours ago
answered 6 hours ago
CousinCocaineCousinCocaine
7203710
7203710
Good ideas, but since your post is not an answer in itself I think you should either elaborate until it's one, or edit a previous answer and put your code in that.
– PetaspeedBeaver
5 hours ago
add a comment |
Good ideas, but since your post is not an answer in itself I think you should either elaborate until it's one, or edit a previous answer and put your code in that.
– PetaspeedBeaver
5 hours ago
Good ideas, but since your post is not an answer in itself I think you should either elaborate until it's one, or edit a previous answer and put your code in that.
– PetaspeedBeaver
5 hours ago
Good ideas, but since your post is not an answer in itself I think you should either elaborate until it's one, or edit a previous answer and put your code in that.
– PetaspeedBeaver
5 hours ago
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.
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%2f225179%2fdisplay-spinner-while-waiting-for-some-process-to-finish%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
