On Sun, 04 Oct 2009 03:03:27 +1100 Sam Watkins <s...@nipl.net>  wrote:
> 
>   find -name '*.c' | xargs cat | cc -     # this clever cc can handle it :)
> 
> This program works fine until there are no .c files to be found, in that case
> it hangs, waiting for one on stdin!  This is a hazard to shell scripters, and
> a potential source of security holes.

Your example doesn't hang (and if it does, your xargs is
broken).  You are thinking of something like this:

$ echo 'cat $*' > foo.sh
$ sh foo.sh

This is not elegant but a reasonable tradeoff.  A common use
of many tools is in a pipeline and having to type - every
time can get annoying. 

To "fix" this you may think of changing your shell to append
/dev/null if a command is given no arguments but that will
fail in cases like `cat -v'.  In unix it is upto each command
to interprets its arguments and a shell can not assume
anything about command arguments.

Reply via email to