0

I am trying to create a while loop that will print "." while a shell script process is running and stop printing when the process has finished. My code continues to print "." after launch.sh has completed.

sh launch.sh & PIDIOS=$!

dot_function() {
running=$(ps aux | grep launch.sh | wc -l)
while [ $running -ge 1 ]; do
   if [ $running -lt 1 ]; then
      break
   elif [ $running -ge 1 ];
      printf "."
      sleep 1
   fi
done
} 
dot_function & PIDMIX=$
1
  • 1
    You're never updating the running variable in your loop. Commented May 11, 2022 at 17:29

1 Answer 1

1

How about using kill -0?

dotwait() {
    while kill -0 "$1" 2>/dev/null
    do
        printf .
        sleep 1
    done
    echo
}

sh launch.sh & dotwait "$!"
Sign up to request clarification or add additional context in comments.

1 Comment

Good question! That works perfectly and much simpler. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.