Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

How to Pause the Shell?

Writer Matthew Harrington

I have a shell script that ends with exit 0 and want to pause it before executing the command.

1

2 Answers

To pause for 3 seconds,

sleep 3
1

Insert this code in your shell script before the line in your shell script that executes the command.

echo "Press any key to continue."
while [ true ] ; do
read -t 10 -n 1
echo ""
if [ $? = 0 ] ; then
exit;
else
echo "Waiting for a keypress..."
fi
done

The code waits 10 seconds for a the user press any key and then prompts the user again to press any key to continue. If three seconds is too long to wait then change the 10 in the line that says read -t 10 -n 1 to a smaller number.

source: revised from Bash wait for keypress

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy