Hi all,

I do not want to make this look as some stupid contest, and intended not
to reply, hoping for the thread to die. But I feel the current state of
it can leave some people with misconceptions.

On Tue, Oct 19, 2004 at 08:40:53PM +0200, [EMAIL PROTECTED] wrote:
> Oron Peled wrote:
> >On Tuesday 19 October 2004 09:33, [EMAIL PROTECTED] wrote:
> >
> >>Yedidyah Bar-David wrote:
> >>
> >>>>That's wrong. If /tmp/tmp-sms contains multiple lines then sendsms
> >>>>would be invoked separatly for each one of them.
> >>
> >>You are right - multiple lines will result in multiple command line 
> >>arguments, not necessarily
> >>
> >>multiple invocations.
> >
> >
> >Hmmm... interesting. Look at that input:
> >
> >  $ cat /tmp/t
> >  me "Shlomo" "hello there,
> >  how are you"
> >
> >It's a multiline [but properly quoted] message. Let's try xargs:
> >
> >  $ xargs cat < /tmp/t
> >  xargs: unmatched double quote

You did not even explain what this error message means. You simply
went on ignoring it, as if it proves your point. Quoting (again)
xargs(1):
"ments  from  the standard input, delimited by blanks (which can be pro-
 tected with double or single quotes or a backslash)  or  newlines,  and
..
 --null, -0
      Input filenames are terminated by a null character instead of by
      whitespace, and the quotes and backslash are not special  (every"
% xargs -0 cat < t
cat: me "Shlomo" "hello there,
how are you"
: No such file or directory
Now it's all one arg. Or, if you prefer, a variation:
% cat t | tr '\012' '\000' | xargs -0 cat
cat: me "Shlomo" "hello there,: No such file or directory
cat: how are you": No such file or directory
Still not what you showed, but you did not exactly define what you want.

> >
> >And now let's try my prior suggestion:
> >
> >  $ eval cat "`cat /tmp/t`"
> >  cat: me: No such file or directory
> >  cat: Shlomo: No such file or directory
> >  cat: hello there, how are you: No such file or directory

This isn't what happens in my shell:
% eval cat "`cat t`"
cat: me: No such file or directory
cat: Shlomo: No such file or directory
cat: hello there,
how are you: No such file or directory
That's bash 3 in Debian sid. The manpage does mention there is an option
to make it behave like what you show, but I do not have time to test
this. It does work as you say with tcsh.

And, BTW - the reason you got what you wanted is because of the 'eval',
not the backquotes. Without it, they will still count as one long word,
or many short ones, depending on whether you put the extra '"' you did
or not. And if you put them, you still get different behaviour in bash3.

> >
> >See how cat(1) got exactly the wanted 3 arguments?
> >
> >Seems like I just won the bash-judo :-)
> >
> 
> I'm not sure who you addressed this to, but that's basically the other
> side of the point I was making - back-quotes eventually flaten the lines
> and allow the shell to include the entire file as a single command-line
> argument, while xargs by definition will pass each input line as a
> separate command line argument, regardless of quotation marks in the
> input.

I know you did not ask me, but I reply anyway. I did not address this
to anyone specifically. I just want to make something clear - unix has
powerful tools. Whatever you do, check well that they do exactly what
you want them to do. Otherwise they will bite you. Both xargs and back
quotes are such tools. I personally know backquotes for a much longer
time (maybe 10 vs 5 years for xargs), but I generally trust xargs more,
because it is way simpler. I do use backquotes all the time,
interactively, but I would think very well before putting them in a
script, with non trivial input.

I will just give one example, which happened to me in real life (as
opposed to our little games). The NEWS file of GNU coreutils mentions,
for version 5.0.90, dated 2003-07-29, that "wc count field widths
now are heuristically adjusted depending on the input size, if known.
If only one count is printed, it is guaranteed to be printed without
leading spaces.". I wrote a little script, that did something like
num=`cmd | wc -l`
if [ "$num" = something ];
..
and which worked well. But not on some older system, on which it had
to run, with an older wc. It did not cause damage, but it took me quite
some time to debug. Since then I have an ugly habbit to always do
num=`prog | wc -l`
num=`echo $num`
just in case it will run on some older system.
One might argue this is a bug in wc - this is quite an old tool, what
was so urgent to change its behaviour after 30 years? My point is that
backquotes involve parsing, which is a complex operation, whereas other,
simpler tools, are more robust. And more than that, do not make
assumptions about such things - read the docs and check thoroughly.

Sorry for a long, boring (?), off-topic message (and thread), HTH,
-- 
Didi


=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to