I would like to use bash process substitution for a sudo command.
For example, here’s a non-sudo command that works for me:
$ cat <(echo "installed.txt")
installed.txt
And here’s a sudo version of the command that does not work:
$ sudo cat <(echo "installed.txt")
cat: /dev/fd/63: Bad file descriptor
Reading the sudo man page, it seems that sudo closes all but the stdin/stdout/stderr file descriptors before running the command as root. This leads me to think that bash is creating the descriptor (and performing the process substitution) before running the sudo command.
I changed root’s shell to bash (instead of sh default). I’ve tested that the command works fine when logged in as root. It only does not work via a sudo command.
What is the appropriate technique to achieve what I’m trying to do here? Eval, quoting, sudo flag, sudoers file mod, other?
Try doing this in your shell :