From mboxrd@z Thu Jan 1 00:00:00 1970 To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> In-reply-to: Your message of "Sun, 04 Oct 2009 03:03:27 +1100." <20091003160327.GA15021@nipl.net> References: <20091003160327.GA15021@nipl.net> From: Bakul Shah Date: Sat, 3 Oct 2009 11:46:16 -0700 Message-Id: <20091003184617.14C075B2E@mail.bitblocks.com> Subject: Re: [9fans] mishandling empty lists - let's fix it Topicbox-Message-UUID: 7ceefd4a-ead5-11e9-9d60-3106f5b1d025 On Sun, 04 Oct 2009 03:03:27 +1100 Sam Watkins 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.