Bugzilla – Bug 263
bash process substitution fails
Last modified: 2007-09-24 12:20:55 MDT
Hello, I changed a shell script to sudo a number of commands. In all but one case this worked fine. After a lot of debugging i finally managed to figure out why it fails. The problem was with the bash process substitution on the original command line. I just downloaded and compiled 1.6.9p5, it also has this problem with bash process substitution. Here's an example of a command and the work-around i'm currently using: $ cat <(ls -al) [MR: This prints the contents of the current directory] $ sudo cat <(ls -al) [MR: This prints "cat: /dev/fd/63: No such file or directory"] $ sudo bash -c "cat <(ls -al)" [MR: This work-around prints the contents of the current directory] It looks like the process substitution is performed before the command line is actually executed by sudo, i'd have expected sudo to take the command line as is and execute it.
This is not a bug. Both the redirection and the substitution are done by the shell before sudo is even run. Now, in this case bash is running "sudo /dev/fd/63" after opening file descriptor 63. The reason this fails is that as part of its sanity checks, sudo closes file descriptors other than 1, 2, and 3 when starting. In sudo 1.7 (still in alpha) it will be possible to control this behavior. However, "sudo cat <(ls -al)" seeme like an odd way to do things. Is there really any reason to not just do "sudo ls -al"? I suppose "sudo ls -al | cat" or "cat <(sudo ls -al)" would work too but I just don't see the reason for using cat in this case.