

The following example shows how you can use prompts to explain what the user should enter. Type the year that you want to check (4 digits), followed by : # This script will test if you have given a leap year or not.Įcho "Type the year that you want to check (4 digits), followed by :" This is a straightforward example, improving on the leaptest.sh script from the previous chapter: michel ~/test> cat leaptest.sh This option has no effect if read is not reading input from the terminal or from a pipe. If input is coming from a terminal, characters are not echoed.Ĭause read to time out and return failure if a complete line of input is not read within TIMEOUT seconds. In particular, a backslash-newline pair may not be used as a line continuation. The backslash is considered to be part of the line. If this option is given, backslash does not act as an escape character. The prompt is displayed only if input is coming from a terminal.

Read returns after reading NCHARS characters rather than waiting for a complete line of input.ĭisplay PROMPT, without a trailing newline, before attempting to read any input. The first character of DELIM is used to terminate the input line, rather than newline. All elements are removed from ANAME before the assignment. The words are assigned to sequential indexes of the array variable ANAME, starting at 0. The following options are supported by the Bash read built-in:
#READ AN INOUT FROM CMD C CODE#
The return code of the read command is zero, unless an end-of-file character is encountered, if read times out or if an invalid file descriptor is supplied as the argument to the -u option. If no names are supplied, the line read is assigned to the variable REPLY. The backslash character may be used to remove any special meaning for the next character read and for line continuation. The characters in the value of the IFS variable are used to split the input line into words or tokens see Section 3.4.8. If there are fewer words read from the input stream than there are names, the remaining names are assigned empty values. The first word of the line is assigned to the first name, NAME1, the second word to the second name, and so on, with leftover words and their intervening separators assigned to the last name, NAMEN. One line is read from the standard input, or from the file descriptor supplied as an argument to the -u option. The syntax of the read command is as follows:

After the final character is retrieved, Read blocks its return again and the cycle repeats.The read built-in command is the counterpart of the echo and printf commands. Subsequent calls to the Read method retrieve your input one character at a time.
#READ AN INOUT FROM CMD C WINDOWS#
Pressing Enter appends a platform-dependent line termination sequence to your input (for example, Windows appends a carriage return-linefeed sequence). The Read method blocks its return while you type input characters it terminates when you press the Enter key. 'Value was either too large or too small for a character. 'This example produces the following results: Type '+' anywhere in the text to quit:\n" Printfn "\nType a string of text then press Enter. "Type '+' anywhere in the text to quit:\n" String^ m1 = "\nType a string of text then press Enter. This example demonstrates the Console.Read() method. The following example demonstrates the Read method.
