-
Notifications
You must be signed in to change notification settings - Fork 19
Description
fdmove 1 1 is correctly a no-op, but fdmove -c will fail if you use the same file descriptor:
$ fdmove 1 1 ls -l /proc/self/fd
total 0
lrwx------ 1 emanuele6 wheel 64 Nov 16 09:23 0 -> /dev/pts/7
lrwx------ 1 emanuele6 wheel 64 Nov 16 09:23 1 -> /dev/pts/7
lrwx------ 1 emanuele6 wheel 64 Nov 16 09:23 2 -> /dev/pts/7
lr-x------ 1 emanuele6 wheel 64 Nov 16 09:23 3 -> /proc/3330198/fd
$ fdmove -c 1 1 ls -l /proc/self/fd
fdmove: fatal: unable to move fd 1 to fd 1: Invalid argumentskalibs's fd_copy(to, from) function hardcodes to == from as a failure instead of returning to for successful no-op if it's positive, or just calling dup2(to, from) and letting it do nothing successfully.
When you are doing something like fdmove -c 1 "$fd", the fact that it fails if fd is 1 is unideal.
Slightly related: fdmove is documented as
On a
fdmove a b prog...is roughly equivalent tosh -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.
I think it could be useful to mention that fdmove a b is not simply equivalent to fdmove -c a b fdclose b, because it is a no-op and won't close b if a == b; more like a<&b- in bash/ksh93 rather than a<&b b<&-.
o/
emanuele6