Sponsored Content
Full Discussion: Read timeout
Top Forums Shell Programming and Scripting Read timeout Post 302924479 by sea on Monday 10th of November 2014 05:27:22 AM
Old 11-10-2014
GNU Bash - Read:
Code:
       read [-ers] [-a aname] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]
              One  line  is read from the standard input, or from the file descriptor fd supplied as an argument to the -u option, and the first word is assigned to the first name, the second word to the second name, and so on, with
              leftover words and their intervening separators assigned to the last name.  If there are fewer words read from the input stream than names, the remaining names are assigned empty values.  The characters in IFS are used
              to split the line into words.  The backslash character (\) may be used to remove any special meaning for the next character read and for line continuation.  Options, if supplied, have the following meanings:
              -a aname
                     The words are assigned to sequential indices of the array variable aname, starting at 0.  aname is unset before any new values are assigned.  Other name arguments are ignored.
              -d delim
                     The first character of delim is used to terminate the input line, rather than newline.
              -e     If the standard input is coming from a terminal, readline (see READLINE above) is used to obtain the line.  Readline uses the current (or default, if line editing was not previously active) editing settings.
              -i text
                     If readline is being used to read the line, text is placed into the editing buffer before editing begins.
              -n nchars
                     read returns after reading nchars characters rather than waiting for a complete line of input, but honor a delimiter if fewer than nchars characters are read before the delimiter.
              -N nchars
                     read  returns after reading exactly nchars characters rather than waiting for a complete line of input, unless EOF is encountered or read times out.  Delimiter characters encountered in the input are not treated
                     specially and do not cause read to return until nchars characters are read.
              -p prompt
                     Display prompt on standard error, without a trailing newline, before attempting to read any input.  The prompt is displayed only if input is coming from a terminal.
              -r     Backslash does not act as an escape character.  The backslash is considered to be part of the line.  In particular, a backslash-newline pair may not be used as a line continuation.
              -s     Silent mode.  If input is coming from a terminal, characters are not echoed.
              -t timeout
                     Cause read to time out and return failure if a complete line of input is not read within timeout seconds.  timeout may be a decimal number with a fractional portion following the decimal point.  This  option  is
                     only  effective if read is reading input from a terminal, pipe, or other special file; it has no effect when reading from regular files.  If timeout is 0, read returns success if input is available on the speci‐
                     fied file descriptor, failure otherwise.  The exit status is greater than 128 if the timeout is exceeded.
              -u fd  Read input from file descriptor fd.

              If no names are supplied, the line read is assigned to the variable REPLY.  The return code is zero, unless end-of-file is encountered, read times out (in which case the return code is greater than 128), or an  invalid
              file descriptor is supplied as the argument to -u.

Code:
read -n 1 -t 5 -p "Type your answer " input

hth
 

10 More Discussions You Might Find Interesting

1. HP-UX

timeout

How can I kick a user out after being idle for a certain amount of time, would prefer not to use scripts, will TMOUT work on HP-UX? (5 Replies)
Discussion started by: csaunders
5 Replies

2. Solaris

About the Timeout

Hello everyone I am a new one,I want to know how to get the solaris force the loginer out if he do not in a time thanks (4 Replies)
Discussion started by: lyh003473
4 Replies

3. Shell Programming and Scripting

Giving "read" from standard input a timeout.

I want to prompt a user for input but I want it to timeout after a specified time if no response is given. I tried the sleep command but this does not work. I am using ksh. Thanks. (10 Replies)
Discussion started by: rello
10 Replies

4. Shell Programming and Scripting

ksh read timeout

any idea on how to timeout the read statement for ksh? for bash u can use read -t option -t timeout Cause read to time out and return failure if a complete line of input is not read within timeout seconds. This option has ... (2 Replies)
Discussion started by: ashterix
2 Replies

5. Shell Programming and Scripting

How to timeout the "read" command

I have a script that at some point will ask the interactive user a question: #!/bin/ksh echo "What is your access code?" read ans ... Sometimes this script is run by other scripts and there are no interactive users. The script then hangs on the "read" command, waiting for a user response... (5 Replies)
Discussion started by: rm-r
5 Replies

6. Red Hat

RPC Timeout

I have a RHEL 2.1 machine that I am trying to get to mount a remote nfs filesystem. Both servers have 2 network interfaces. My linux machine can mount the filesystem through one interface with no problems but if I switch over and try to mount it through the other interface using a totally... (1 Reply)
Discussion started by: darren.wyatt
1 Replies

7. Shell Programming and Scripting

read from std i/p with timeout within a script

hello every one , this is my first participation in the forum , I hope it'll be a good start within a script I would like to put some code to read i\p from standard i\p using read command if it reads Y it will terminate the script if it reads N it will continue execution , if no i\p is... (2 Replies)
Discussion started by: Blue_shadow
2 Replies

8. Boot Loaders

read sectors from disk failed with timeout

i'm writing some code to simulate the boot progress after power on but when i try to read the 2nd sector from a floppy disk, this operation always fail with ah=0x80h which means timeout, how can i get over this problem? my code would be like this: $ cat boot.S .code16 #define SETUPLEN 4... (0 Replies)
Discussion started by: wljackhero
0 Replies

9. Linux

read sectors from disk failed with timeout

i'm writing some code to simulate the boot progress after power on but when i try to read the 2nd sector from a floppy disk, this operation always fail with ah=0x80h which means timeout, how can i get over this problem? my code would be like this: $ cat boot.S .code16 #define SETUPLEN 4... (0 Replies)
Discussion started by: wljackhero
0 Replies

10. UNIX for Advanced & Expert Users

read sectors from disk failed with timeout

i'm writing some code to simulate the boot progress after power on but when i try to read the 2nd sector from a floppy disk, this operation always fail with ah=0x80h which means timeout, how can i get over this problem? my code would be like this: $ cat boot.S .code16 #define SETUPLEN 4... (0 Replies)
Discussion started by: wljackhero
0 Replies
read(n) 						       Tcl Built-In Commands							   read(n)

__________________________________________________________________________________________________________________________________________________

NAME
read - Read from a channel SYNOPSIS
read ?-nonewline? channelId read channelId numChars _________________________________________________________________ DESCRIPTION
In the first form, the read command reads all of the data from channelId up to the end of the file. If the -nonewline switch is specified then the last character of the file is discarded if it is a newline. In the second form, the extra argument specifies how many characters to read. Exactly that many characters will be read and returned, unless there are fewer than numChars left in the file; in this case all the remaining characters are returned. If the channel is configured to use a multi-byte encoding, then the number of characters read may not be the same as the number of bytes read. ChannelId must be an identifier for an open channel such as the Tcl standard input channel (stdin), the return value from an invocation of open or socket, or the result of a channel creation command provided by a Tcl extension. The channel must have been opened for input. If channelId is in nonblocking mode, the command may not read as many characters as requested: once all available input has been read, the command will return the data that is available rather than blocking for more input. If the channel is configured to use a multi-byte encoding, then there may actually be some bytes remaining in the internal buffers that do not form a complete character. These bytes will not be returned until a complete character is available or end-of-file is reached. The -nonewline switch is ignored if the command returns before reaching the end of the file. Read translates end-of-line sequences in the input into newline characters according to the -translation option for the channel. See the fconfigure manual entry for a discussion on ways in which fconfigure will alter input. USE WITH SERIAL PORTS
For most applications a channel connected to a serial port should be configured to be nonblocking: fconfigure channelId -blocking 0. Then read behaves much like described above. Care must be taken when using read on blocking serial ports: read channelId numChars In this form read blocks until numChars have been received from the serial port. read channelId In this form read blocks until the reception of the end-of-file character, see fconfigure -eofchar. If there no end-of-file charac- ter has been configured for the channel, then read will block forever. EXAMPLE
This example code reads a file all at once, and splits it into a list, with each line in the file corresponding to an element in the list: set fl [open /proc/meminfo] set data [read $fl] close $fl set lines [split $data ] SEE ALSO
file(n), eof(n), fblocked(n), fconfigure(n), Tcl_StandardChannels(3) KEYWORDS
blocking, channel, end of line, end of file, nonblocking, read, translation, encoding Tcl 8.1 read(n)
All times are GMT -4. The time now is 01:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy