Display Spinner while waiting for some process to finish

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












5















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?










share|improve this question


























    5















    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?










    share|improve this question
























      5












      5








      5


      4






      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?










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 24 '15 at 17:03







      user88036



























          2 Answers
          2






          active

          oldest

          votes


















          10














          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





          share|improve this answer


















          • 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


















          7














          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





          share|improve this answer























          • See also stackoverflow.com/a/20369590/2908724

            – bishop
            Oct 21 '16 at 17:28










          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
          );



          );













          draft saved

          draft discarded


















          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









          10














          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





          share|improve this answer


















          • 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















          10














          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





          share|improve this answer


















          • 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













          10












          10








          10







          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





          share|improve this answer













          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






          share|improve this answer












          share|improve this answer



          share|improve this answer










          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












          • 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













          7














          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





          share|improve this answer























          • See also stackoverflow.com/a/20369590/2908724

            – bishop
            Oct 21 '16 at 17:28















          7














          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





          share|improve this answer























          • See also stackoverflow.com/a/20369590/2908724

            – bishop
            Oct 21 '16 at 17:28













          7












          7








          7







          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





          share|improve this answer













          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






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Apr 14 '16 at 21:03









          jsearsjsears

          17114




          17114












          • 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





          See also stackoverflow.com/a/20369590/2908724

          – bishop
          Oct 21 '16 at 17:28

















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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






          Popular posts from this blog

          Peggy Mitchell

          Palaiologos

          The Forum (Inglewood, California)