Chapter 4: Shell Builtin Commands

55

%(datefmt)T

Causes printf to output the date-time string resulting from using datefmt as a format string for strftime(3). The corresponding argument is an integer representing the number of seconds since the epoch. Two special argument values may be used: -1 represents the current time, and -2 represents the time the shell was invoked.

If no argument is specified, conversion behaves as if -1 had been given. This is an exception to the usual printf behavior.

Arguments to non-string format specifiers are treated as C language constants, except that a leading plus or minus sign is allowed, and if the leading character is a single or double quote, the value is the ASCII value of the following character.

The format is reused as necessary to consume all of the arguments. If the for- mat requires more arguments than are supplied, the extra format specifications behave as if a zero value or null string, as appropriate, had been supplied. The return value is zero on success, non-zero on failure. read 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 the value of the IFS variable are used to split the line into words using the same rules the shell uses for expansion (described above in Section 3.5.7 [Word Splitting], page 29). The backslash character ‘\’ may be used to remove any special meaning for the next character read and for line continuation. 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), a variable assignment error

(such as assigning to a readonly variable) occurs, or an invalid file descriptor is supplied as the argument to -u.

Options, if supplied, have the following meanings:

-a aname

The words are assigned to sequential indices of the array variable aname, starting at 0. All elements are removed from aname before the assignment. Other name arguments are ignored.

-d delim

The first character of delim is used to terminate the input line, rather than newline.

-e

Readline (see Chapter 8 [Command Line Editing], page 101) 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.