Results 1 to 4 of 4
Hello all,
I'm writing a script that prompts user to insert a blank cd to the cd drive and ask user to hit enter when done, otherwise the the script ...
- 08-18-2008 #1Linux User
- Join Date
- May 2008
- Location
- NYC, moved from KS & MO
- Posts
- 251
script waiting for user to hit enter
Hello all,
I'm writing a script that prompts user to insert a blank cd to the cd drive and ask user to hit enter when done, otherwise the the script will beep every second, what I came up with so far is
The problem with this script is that it beeps only once, then waits for user's input. I think the line in bold is causing the problem because it won't exit until something is entered. Is there a way to fix this? Any suggestions are welcome. I'm running OpenSuSE 10.3.Code:#!/bin/bash while true; do echo "Insert a blank cd, hit enter to continue" echo -en '\a' > /dev/console read -n 1 keypress if [ "$keypress" == "" ]; then break fi sleep 1 done #to run rest of the code
- 08-19-2008 #2Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
1) type "help read"
2) understand what you are reading
3) notice the option "-t" for "timeout"
4) success!
- 08-19-2008 #3Linux User
- Join Date
- May 2008
- Location
- NYC, moved from KS & MO
- Posts
- 251
Hey burschik,
I should have read the manual for read command more carefully. Thanks for the direction. I've solved the problem with the following code:
Code:#!/bin/bash [ ! `whoami` == "root" ] && echo "must be root to run this script" && exit 1 keypress="a" echo "Insert a blank cd, hit enter to continue" until [[ $keypress == '' ]]; do echo -en '\a' > /dev/console read -t 1 -n 1 keypress done
- 08-19-2008 #4Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
You're welcome.


Reply With Quote