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

Re: PATCH: <<<: Document newline behavior and fix optimization



2022-03-08 11:42:31 -0800, Bart Schaefer:
> On Tue, Mar 8, 2022 at 11:38 AM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> >
> > I regularly make use of the fact that <<<foo does not add a newline
> 
> Or, hmm, I thought I did, but that can't be.  What am I thinking of?

In Byron Rakitzis's clone of rc, <<< does not add a newline. I
heard here that that's the shell that introduced <<<, though
I've not found evidence of the fact that rc had it before zsh.

Maybe you were thinking of "$(<<<foo)" which strips trailing
newline*S* just like "$(echo foo)". The fact that it strips more
than one newline is a misfeature IMO though (shared by all
Bourne-like shells). That makes it that things like

dir=$(dirname -- "$file")

Are incorrect as they fail for files whose dirname ends in
newline characters (and why you want to use dir=$file:h instead
if you're lucky enough to use zsh).

I was thinking at some point maybe we could add a
$CMDSUB_RTRIM special variable, which one could set to $'\n' (or
$'(\r|)\n' for MSDOS users) instead of the default of $'\n#'
to allow users to fix that problem.

-- 
Stephane




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