Re: cut off last lines of a document

From: Andreas Kusalananda Kähäri <andreas.kahari_at_abc.se>
Date: Mon, 04 Sep 2023 15:24:00 UTC
Sorry, this is resent due to a misconfiguration of my mail client.

On Mon, Sep 04, 2023 at 04:54:14PM +0200, Dag-Erling Smørgrav wrote:
> "Andreas Kusalananda Kähäri" <kusalananda.kahari@gmail.com> writes:
> > Note how this will handle backslash-escaped newlines in the input, and
> > that, depending on the shell and its configuration, the "echo" call may
> > or may not expand backslash-escaped characters in the input (e.g. "\n"
> > and "\t").  The "echo" may also interpret the string "-n" as an option
> > it occurs on its own line.  You may also lose flanking whitespace.
> 
> Right.  If your shell is broken, use read -r and replace echo with
> printf "%s\n".  Or don't use a broken shell.
> 
> DES
> -- 
> Dag-Erling Smørgrav - des@FreeBSD.org

Don't forget to also set IFS to an empty string.

Apart from the issue that comes from having a too feature-full
"echo" implementation, the rest of the issues are due to the POSIX
specifications of the "read" utility.  If POSIX is broken or not is a
discussion I'm not getting into.



-- 
Andreas (Kusalananda) Kähäri
SciLifeLab, NBIS, ICM
Uppsala University, Sweden

.