rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
* (much) more help on quoting
@ 1991-08-28 14:22 malte
  1991-08-28 17:48 ` John Mackin
  0 siblings, 1 reply; 2+ messages in thread
From: malte @ 1991-08-28 14:22 UTC (permalink / raw)
  To: rc

Ok, once again. I already received some answers to may request for help
on quoting. I assumed that my /bin/sh example was easy to understand.
So, a little more detailed:

	prg -sample "`cat file`"	(sh)

calls prg with _2_ arguments, "-sample", "the contents of file".
The second argument is a bytewise copy of files contents.

What I already have tried (rc):

	prg -sample '`{ cat file }'

doesn't execute `{ cat file }, as expected.

	prg -sample ''`{ cat file }''

gives all the words in file as single arguments to prg with leading and
trailing null strings, as expected.

	prg -sample '''`{ cat file }'''

as above, but leading and trailing "'"s. Adding more quotes adds more null
strings or "'"s, as expected. Applying eval to these lines just shifts
the quoting problem.

	prg -sample (`{ cat file })

Well, I not sure about that. Fact is, that each word in file is a single
argument.

	tmp=`{ cat file }
	prg -sample $^tmp

This passes the contents of file as a single argument, but applies $ifs,
drops "\n" and other control characters, in short, doesn't leave file
untouched.


I hope this makes it clear, especially for those who answered in an
insulting style.

Malte



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: (much) more help on quoting
  1991-08-28 14:22 (much) more help on quoting malte
@ 1991-08-28 17:48 ` John Mackin
  0 siblings, 0 replies; 2+ messages in thread
From: John Mackin @ 1991-08-28 17:48 UTC (permalink / raw)
  To: The rc Mailing List

Hey, wow, there seems to be a lot of confusion here.  Let me see if I can
cut through some of it (without insulting anyone :).  Malte writes:

    Ok, once again. I already received some answers to may request for help
    on quoting. I assumed that my /bin/sh example was easy to understand.

It was -- but what I understood from it is _different_ to what you seem
to understand from it.  That's why I didn't answer your mail before: since
I could see no really good way to do the same thing in rc, and was waiting
for someone else to speak up.  Unfortunately, whoever did didn't reply
to the list: I imagine they also failed to realise just how subtle this
whole issue is.

    So, a little more detailed:

    	prg -sample "`cat file`"	(sh)

    calls prg with _2_ arguments, "-sample", "the contents of file".
    The second argument is a bytewise copy of files contents.

Whoa!  Hold it _right there_!  Not in any version of sh _I_ have access
to, it isn't!!!!  Two arguments, indeed, but the second one is most
certainly NOT a verbatim copy of the file's contents: _it is a copy
of the file's contents _with the terminal newline removed__!!!  This
is truly bizarre behaviour (although it might be what you want) and
is hard (I think) to reproduce in rc.  (In all following examples, I
will use $nl to represent a single newline, for clarity.)  I think,
Malte, with all due respect, that you are confused, and that this
is really what you meant: there is no way I can see that some versions
of the shell fail to elide the trailing newline.  So, if in sh we
write:

	echo hello there >a
	cat `cat a`

We get what we expect (modulo cat's error messages differing in detail):

	cat: hello: not found
	cat: there: not found

Now, when we write

	cat "`cat a`"

we get

	cat: hello there: not found

and absolutely NOT what we would get if the above claim is correct,
which would be:

	cat: hello there
	: not found			# WE DON'T GET THIS

I am sure we all see the point here.  Now, we can establish that it
is only the _terminal_ newline that is treated specially:

	echo jim lad >>a
	# a now has "hello there\njim lad\n"
	cat "`cat a`"

and we get

	cat: hello there
	jim lad: not found

This behaviour is hard to emulate in rc (I'd be quite willing to stand
corrected -- I mean, I don't think it can be done just inside rc, without
spawning random other stuff), _unless the file is known to contain
exactly one line_, in which case setting ifs to $nl emulates the
sh behaviour with total precision, so that Malte's command becomes:

	prg -sample `` $nl { cat file }

I stress, however, that this ONLY works if the file is guaranteed to
contain exactly one line.  We can almost emulate the sh behaviour,
modulo the trailing newline elision, by the very beautiful (well,
at least in my font) method of setting ifs to a null string:

	prg -sample ``'' { cat file }

But then we get the trailing newline, which is not in fact what we
want.  (Malte, if in fact your original statement of how "`...`"
worked in your sh was correct (which I very much doubt), then this
command gives you what you want: an argument consisting of the
exact same bytes that are in the file, completely unchanged.)

    What I already have tried (rc):

    	prg -sample '`{ cat file }'

    doesn't execute `{ cat file }, as expected.

All I can say, and sincerely without any wish to insult you, is that if
you expected that to execute the backquote operator, you badly need to
print off Duff's paper and read it carefully, since you are missing
the whole point of why rc is a good program.

The other tries listed after that I am not going to comment on.

OK,
John.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1991-08-28 18:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1991-08-28 14:22 (much) more help on quoting malte
1991-08-28 17:48 ` John Mackin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).