zsh-users
 help / color / mirror / code / Atom feed
* using \r in a while statement
@ 2000-09-23  0:41 Alan Third
  2000-09-23  6:11 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Alan Third @ 2000-09-23  0:41 UTC (permalink / raw)
  To: zsh-users

I have a script which takes a usenet message id as an argument
and then downloads the message and sends it to a pager.
My current problem is testing for the end of the news article.
I'm using a while loop to read in the article a line at a time.
The article is ended by a line which only has .\r\n on it, so
the while statment looks a bit like:

while [[ $LINE != ".\r" ]]; do
    readline
    printline
done

Unfortunately this doesn't work.
I found if I used ^Q^M in emacs I could insert the actual code in
place of the \r and this works, but it means that if someone looks
at my code on my web page then it looks all strange and I'm sure
that it won't download properly.

I've ended up with:
while [[ $LINE != `echo ".\r"` ]]; do
    readline
    printline
done

which works, but I was wondering if anyone could think of a better
way of doing it?

Thanks...
-- 
Alan Third


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

* Re: using \r in a while statement
  2000-09-23  0:41 using \r in a while statement Alan Third
@ 2000-09-23  6:11 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2000-09-23  6:11 UTC (permalink / raw)
  To: Alan Third, zsh-users

On Sep 23,  1:41am, Alan Third wrote:
} Subject: using \r in a while statement
}
} I'm using a while loop to read in the article a line at a time.
} The article is ended by a line which only has .\r\n on it, so
} [...] I've ended up with:
} while [[ $LINE != `echo ".\r"` ]]; do
}     readline
}     printline
} done

If you have zsh 3.1.4 or later, use $'\r' as in [[ $LINE != $'.\r' ]].
The meaning of $'STRING' is that STRING is expanded as if with the
print builtin.

If you have an older zsh, you can still do it, with a considerably less
comprehensible syntax: [[ $LINE != ${(pr(2)(\r)):-.} ]]

Which means, working from the :- outward: expand nothing, and if you
get back nothing (which you must), then replace that with a dot, and
then pad that on the right with \r so the result is 2 characters wide,
interpreting the \r as if it were output by the print builtin.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

end of thread, other threads:[~2000-09-23  6:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-09-23  0:41 using \r in a while statement Alan Third
2000-09-23  6:11 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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).