execline
Software
skarnet.org
The < program
< redirects a given file descriptor to a file, then
executes a program.
Interface
< [ -r | -w | -u | -a | -c | -x ] [ -n | -b ] fd file prog...
< redirects the file descriptor number fd
to file, then execs into prog....
Options
One and only one of the -r, -w, -u, -a, -c, or -x options must be given;
the -n and -b options may be added in any case.
- -r : open file for reading.
- -w : open file for writing, truncating it if it already exists.
- -u : open file for reading and writing.
- -a : open file for appending, creating it if it doesn't exist.
- -c : open file for appending. Do not create it if it doesn't exist.
- -x : open file for writing, creating it, failing if it already exists.
- -n : open file in non-blocking mode.
- -b : change mode of file after opening it:
to non-blocking mode if the -n option was not given,
to blocking mode if it was.
Notes
- < -r n file prog... is roughly equivalent to
sh -c 'exec prog... n<file'
- < -w n file prog... is roughly equivalent to
sh -c 'exec prog... n>file'
- < -u n file prog... is roughly equivalent to
sh -c 'exec prog... n<>file'
- < -a n file prog... is roughly equivalent to
sh -c 'exec prog... n>>file'
- < -c n file prog... has no portable
shell equivalent. Some shells provide the noclobber option for
a similar feature.
- < -x n file prog... has no portable
shell equivalent.
Special fifo handling
The -n and -b options are especially useful with
named pipes.
- Opening a fifo for reading, blocking if there is no writer:
< -r n fifo prog...
- Opening a fifo for reading, with instant success even if
there is no writer, and blocking at the first attempt to read from it:
< -r -nb n fifo prog...
- Opening a fifo for writing, blocking if there is no reader:
< -w n fifo prog...
- Opening a fifo for writing, with instant success even if
there is no reader:
< -w -nb n fifo prog.... Warning:
the first attempt to write to the fifo will raise a SIGPIPE if there is
still no reader at that time. The named pipe semantics normally do not
allow a fifo to be open for writing without a reading end, and you
should know what you are doing if you're using <
this way.