Differences between revisions 1 and 2
Revision 1 as of 2007-05-02 23:59:39
Size: 323
Editor: redondos
Comment:
Revision 2 as of 2008-04-30 10:12:50
Size: 808
Editor: Lhunath
Comment: Improved examples and some more explanation.
Deletions are marked like this. Additions are marked like this.
Line 4: Line 4:
No, but you can use these: Use the following to wait until the user presses enter:
Line 6: Line 6:
echo press enter to continue; read read -sp "Press [enter] to continue..."
Line 8: Line 8:

Or use the following to wait until the user presses any key to continue:
Line 9: Line 11:
echo press any key to continue; read -n 1 read -sn 1 -p "Press any key to continue..."
Line 11: Line 13:

If you want to put a timeout on that, use the `-t` option to `read`:
Line 12: Line 16:
read -p 'press enter to continue' echo "WARNING: You are about to do something stupid."
if ! read -sn 1 -t 5 -p "Will resume in 5 seconds. Press any key to abort..."
then something_stupid
fi
Line 14: Line 21:

For those of you who just want to pause for a while, regardless of the user's input, use `sleep`:
{{{
echo "The script is tired. Please wait a minute."
sleep 60
}}}

Anchor(faq65)

Is there a "PAUSE" command in bash like there is in MSDOS batch scripts? To prompt the user to press any key to continue?

Use the following to wait until the user presses enter:

read -sp "Press [enter] to continue..."

Or use the following to wait until the user presses any key to continue:

read -sn 1 -p "Press any key to continue..."

If you want to put a timeout on that, use the -t option to read:

echo "WARNING: You are about to do something stupid."
if ! read -sn 1 -t 5 -p "Will resume in 5 seconds.  Press any key to abort..."
then something_stupid
fi

For those of you who just want to pause for a while, regardless of the user's input, use sleep:

echo "The script is tired.  Please wait a minute."
sleep 60

BashFAQ/065 (last edited 2013-04-08 12:28:58 by geirha)