Display Spinner while waiting for some process to finish

Clash Royale CLAN TAG#URR8PPP
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 |
2 Answers
2
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 temp
while ps a
("$@") &
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 |
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
2 Answers
2
active
oldest
votes
2 Answers
2
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
41.1k1056131
41.1k1056131
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 temp
while ps a
("$@") &
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 temp
while ps a
("$@") &
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 temp
while ps a
("$@") &
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 temp
while ps a
("$@") &
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 |
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