> firstly, I want to ask you a question of how the command "rm" accept
> the standard output ?
We will come back to that question.
> then, report the bug:
> when I execute the following command, something interesting
> happened:
> $rm<(ls somefilename)
> bash: rm/dev/fd/3: No such file or directory
This looks to be expected. You left out a space between the 'rm' and
the '<(ls somefilename)' which caused them to be jammed together. The
man page for bash says:
Process Substitution
Process substitution is supported on systems that support named pipes
(FIFOs) or the /dev/fd method of naming open files. It takes the form
of <(list) or >(list). The process list is run with its input or
output connected to a FIFO or some file in /dev/fd. The name of this
file is passed as an argument to the current command as the result of
the expansion. If the >(list) form is used, writing to the file will
provide input for list. If the <(list) form is used, the file passed
as an argument should be read to obtain the output of list.
And so the 'ls somefilename' will be attached to a FIFO/PIPE on the
system. This will be /dev/fd/3 in your case but will be different on
different systems. The name of that FIFO will replace the '<(...)' on
the command. The resulting command line is 'rm/dev/fd/3' which the
shell then tries to execute as a command. It can't find it and
reports and error. This is normal, expected and desired behavior.
I don't understand what you were trying to accomplish with the remove
of the fifo. I realize this is condensed from a larger problem. But
just by itself this is not right. In general I suggest you test your
command with the echo command. echo rm<(ls somefilename) will
illustrate your example. But even with the space echo rm <(ls somefilename)
will show that 'rm /dev/fd/3' is not right either.
The process substitution is designed to be useful in cases like this:
fgrep -f <(awk '{print$1}' file1) file2
If I said that right it will perform the first part inside of <(...)
which would normally need the output saved in a temporary file and
hand it to the second part where '<(...)' is replaced with the name of
a file, FIFO but looks like a file. The second part reads the file
which is the output of the first part. This normally needs explicit
temporary files to accomplish but now uses implicit files handled by
the shell. The shell will handle all temporary files. It unburdens
the user from setting traps to catch signals to clean up temporary
files, etc.
> firstly, I want to ask you a question of how the command "rm" accept
> the standard output ?
The rm command does not accept standard input. You can simulate it
using the xargs command.
ls -1 somefilename | xargs echo rm
I put the echo command there to say that you should always test your
commands carefully before rolling them out. Especially with an rm
command. Using xargs with newline terminated strings is inheritly a
problem since newlines are valid filename characters. You can use
find -print0 coupled with xargs -0 to use null terminated names
instead. Read the man/info pages for more information.
find somefilename -print0 | xargs -0 echo rm
Bob Proulx