The fdmove program
fdmove moves or copies a given file descriptor, then executes a program.
Interface
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.
Options
- -c : duplicate fdfrom to fdto instead of moving it; do not close fdfrom.
Notes
- 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!
