REDIRFD(1)

NAME
redirfd - redirect a given file descriptor to a file, then execute a program

SYNOPSIS
redirfd [-r | -w | -u | -a | -x] [-n] [-b] fd file prog...

DESCRIPTION
redirfd redirects the file descriptor number fd to file, then exec(3) s into prog....

•   ‘redirfd -r n file prog...’ is roughly equivalent to ‘sh -c 'exec prog... n<file'’

•   ‘redirfd -w n file prog...’ is roughly equivalent to ‘sh -c 'exec prog... n>file'’

•   ‘redirfd -u n file prog...’ is roughly equivalent to ‘sh -c 'exec prog... n<>file'’

•   ‘redirfd -a n file prog...’ is roughly equivalent to ‘sh -c 'exec prog... n>>file'’

•   ‘redirfd -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:

    redirfd -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:

    redirfd -r -nb n fifo prog...

•   Opening a fifo for writing, blocking if there is no reader:

    redirfd -w n fifo prog...

•   Opening a fifo for writing, with instant success even if there is no reader:

    redirfd -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 redirfd this way.

OPTIONS
One and only one of the -r, -w, -u -a, 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.

-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.

SEE ALSO
emptyenv(1), envfile(1), exec(1), execline-cd(1), execline-umask(1), exit(1), export(1), fdblock(1), fdclose(1), fdmove(1), fdreserve(1), fdswap(1), getcwd(1), getpid(1), heredoc(1), piperw(1), posix-cd(1), posix-umask(1), trap(1), tryexec(1), unexport(1), wait(1), withstdinas(1), exec(3)

This man page is ported from the authoritative documentation at: https://skarnet.org/software/execline/redirfd.html

AUTHORS
Laurent Bercot Alexis <flexibeast@gmail.com> (man page port)