Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: line continuation with sed



Thanks for the replies all:

	$ ls filename\ ending\ with\ a\ space\ <enter>

Ok, so it's an overload of the backslash, which might mean an escaped character, or might indicate line continuation.  I think in my example there'd be no difference but I understand your example where ... mind, people who end a filename with a space aren't fit to live ... but linux isn't going to stop you from doing it, so that case must be accommodated.  So then *only* 'backslash-newline' is a line continuation and any other variant leaves the backslash as an escape, yes?

Playing with it a bit more, sending the command to history and then recalling it I see the defect:


$ junk="now is the time
for all good men
to come to the aid
of the party"

... now run this script:

aa="print -l ${(q)junk} | sed \
-nre s/all/most/p \
-e s/men/persons/p \
-e s/aid/assistance/p"

print -rS "$aa"
eval $aa

... and get:

$ . test
for most good men
for most good persons
to come to the assistance

... recalling from history it works fine, but if I modify the '$aa' command with the 'backslash-space-newline' the recalled command looks like this:

print -l now\ is\ the\ time$'\n'for\ all\ good\ men$'\n'to\ come\ to\ the\ aid$'\n'of\ the\ party | sed -nre s/all/most/p -e s/men/persons/p \
-e s/aid/assistance/p

... so the bleeding backslash is literal ... I guess that's because the space does not 'escape'? ... but I thought you could put a backslash before any character?  Anyway we get a literal backslash and then a literal newline and naturally things go sour.  All this to accommodate servants of the Evil One who would end a filename with a space!

Seriously, I get it, thanks guys.  I don't like it, but i can see what gets feed to sed, and why it goes wrong, invisibly.

Peter:

You can configure a number of editors to show this up.  In emacs,
for example, I use:

(setq-default show-trailing-whitespace t)

... I know it, but after my Debian upgrade whereas my editor used to show a nice little 'return' character/icon, it now shows a 'LF" backlit in white that's so annoying I turned it off :( ... so I'm a victim of that mistake.  I'd normally remove trailing spaces just to be tidy, nevermind disasters like the above.












Messages sorted by: Reverse Date, Date, Thread, Author