The fdmove program
fdmove moves or copies a given file descriptor, then
executes a program.
fdmove [ -c ] fdto fdfrom prog...
fdmove moves the file descriptor number fdfrom,
to number fdto, then execs into prog with its arguments.
If fdto is open, fdmove closes it before moving
fdfrom to it.
- -c : duplicate fdfrom to fdto
instead of moving it; do not close fdfrom.
- fdmove a b prog... is roughly equivalent to
sh -c 'exec prog... a>&b b<&-'.
It means: if you write to fd a now, it will have the same effect as writing
to fd b beforehand, and you cannot write to fd b anymore.
- fdmove -c a b prog... is roughly equivalent to
sh -c 'exec prog... a>&b'. It means: you can
now write to fd a, and also still write to fd b, and both will have
the same effect as writing to fd b beforehand.
- It also works with file descriptors that are open for reading!