How to Pause the Shell?
Matthew Harrington
I have a shell script that ends with exit 0 and want to pause it before executing the command.
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
doneThe 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