![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Development Releases: Linux Mint 4.0 Beta "Fluxbox", 4.0 Alpha "Debian" | iBot | UNIX and Linux RSS News | 0 | 01-04-2008 12:00 PM |
| Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" | Lokesha | UNIX for Dummies Questions & Answers | 4 | 12-19-2007 10:52 PM |
| "Trap 3e" OBP error on Ultra 5. | akbar | SUN Solaris | 2 | 04-17-2007 10:38 PM |
| "trap" password expiration message | MizzGail | UNIX for Dummies Questions & Answers | 2 | 03-24-2006 05:50 AM |
| No utpmx entry: you must exec "login" from lowest level "shell" | peterpan | UNIX for Dummies Questions & Answers | 0 | 01-18-2006 01:15 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi,
I picked up a shell script function to implement a read timeout functionality : Wait for specified number of seconds to read input, else return. E.g: read_timeout 5 localvar This would wait for 5 seconds to get a user input, and will exit if no input is given for 5 seconds. The localvar variable would become null in the timed out case. The code goes as : read_timeout() { trap : USR1 trap 'kill "$pid" 2> /dev/null' EXIT (sleep "$1" && kill -USR1 "$$") & pid=$! read "$2" ret=$? kill "$pid" 2> /dev/null trap - EXIT return "$ret" } Inside this function, I want to set the input variable to a default value if the time out happens. E.g. : With the statement read_timeout 5 localvar localvar should become equal to "nothing" if I do not enter any value for 5 seconds. This is not happening if a set localvar = nothing before invoking the read_timeout function Is it possible with this piece of code? Thanks, Puneet Arora |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
bash has a read -t seconds builtin. It does exacatly what you want.
|
||||
| Google The UNIX and Linux Forums |