I have a simple Unix shell script which is executing a time-consuming find command. Till it executes, my script appears non-responsive. However it's actually running in reality.
How can I add a progress bar or print dots till the find command is executing?
I want to print some dots or hash till the function doSomething is executing.
function doSomething()
{
# Time-consuming 'for' loop below
for var in `find XXXXXX`
do
# Some more processing
done;
}
# Call the function doSomething. Need the progress DOTS till doSomething is executing
doSomething
# Remaining script processing
I have tried to google, but none of the solutions fits what I am trying to achieve. Any suggestions?
You can run a spinner in the background
#!/usr/bin/env bash
spinner() {
local s="|/-\\"
local -i i=0
while :; do
printf "%s\\r" "${s:i++%4:1}" >&2
sleep .05
done
}
function doSomething()
{
# time consuming for loop below
while read -r -d '' var
do
: #some more processing
done < <(find XXXXXX -print0)
}
# Start the spinner in the background
spinner &
# Get the spinner PID
spinner_pid=$!
#call the function doSomething. Need the progress DOTS till doSomething is executing
doSomething
# Terminate the background running spinner
kill $spinner_pid
# remaining script processing
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With