How to Pause the Shell?

How to Pause the Shell?

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

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

Marcus Vance
Author

Marcus Vance

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.