Reputation: 242
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=$
Upvotes: 0
Views: 792
Reputation: 16865
How about using kill -0
?
dotwait() {
while kill -0 "$1" 2>/dev/null
do
printf .
sleep 1
done
echo
}
sh launch.sh & dotwait "$!"
Upvotes: 1