Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: indented heredocs
- X-seq: zsh-workers 40222
- From: Dave Yost <Dave@xxxxxxxx>
- To: zsh workers <zsh-workers@xxxxxxx>
- Subject: Re: indented heredocs
- Date: Wed, 21 Dec 2016 12:38:19 -0800
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:mime-version:subject:date:references:to:in-reply-to :message-id; bh=1PxlY5SjN0oh+WeYlEZqbMSP851/9rwzLgK9gOfthdY=; b=ptb2g1piPttmClEHDwzyzIZ8tjBhOvuRhPqYHo5YbbPc0OckP+BBsj2/T0E5P325ff kS/PEogaVZBRQddfBrtOsuNaApK+r6KxYJtCDMhPlfTUHaCUL4LKJI2vnL+EkNV9Z3tH URVJuTM2f6B3p8yoxYyaH7aCd+x1ZT7wGd8Fm5z2QDhZQmJntmqBX5vEC6z2c4kYl/Tk /HtyreMhf2TZ0kj/n524dYL+8aXRaFH0FUoNp+2pI2WiAI4HDyCoRdWHcuPrdqFGRVyW vzu1XMWKB42G8l0dKHNtOChcatePg1iPkllavsQujYquAFX55WL8mtChg5VamVnaIF94 s+eA==
- In-reply-to: <CFA2339B-26F2-4104-AAD2-64852509286B@yost.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CFA2339B-26F2-4104-AAD2-64852509286B@yost.com>
- Sender: Dave Yost <daveyostcom@xxxxxxxxx>
I should mention that <<- is defined to remove all leading tabs in the heredoc, so you get this:
0 Wed 12:34:44 yost DaveBook ~
215 Z% cat <<-xx
heredocd> a
heredocd> b
heredocd> xx
a
b
0 Wed 12:35:35 yost DaveBook ~
216 Z%
so if you intended the line containing “a” to have a leading tab, you will not get what you want. This is a misfeature IMO.
Also: the examples below don’t show the “heredocd>” prefix because I pasted the entire input into the terminal before hitting return.
Dave
> On 2016-12-21, at 11:29 AM, Dave Yost <dave@xxxxxxxx> wrote:
>
> Today we have this:
>
> 0 Wed 10:53:18 ~
> 204 Z% cat <<xx
> foo
> bar
> xx
> foo
> bar
> 0 Wed 10:53:33 ~
> 205 Z%
>
> Surely people have thought of this (Alternative 1):
>
> 0 Wed 10:53:53 ~
> 205 Z% cat <<xx
> foo
> bar
> xx
> foo
> bar
> 0 Wed 10:53:53 ~
> 206 Z%
>
> but shells don’t do that.
>
> I ran this idea by Steve Bourne and asked him why indenting was not allowed.
>
>> I never considered the indent idea. It's a good idea although I don't like the idea of post processing the temp file to remove the
>> leading white space. I agree the way it is now is not easy to look at, and I can't think of a way to have the ident amount specified
>> in advance of reading the document.
>
>
> BTW, of historical interest, he also said he stole the heredoc idea from somebody else at Cambridge <https://www.youtube.com/watch?v=FI_bZhV7wpI#t=21m8s>.
>
> I suggested this (Alternative 2), which he liked:
>
> 0 Wed 10:53:53 ~
> 206 Z% cat \
> <<xx
> foo
> bar
> xx
> foo
> bar
> 0 Wed 10:54:10 ~
> 207 Z%
>
> He also suggested
>
>> You could find another symbol after < Right now <xxx is file <<yyy is heredoc <<< is string. Other meta symbols
>> are available which now would cause syntax error.
>
>
> I don’t think that would help anything. If the parser doesn’t know how to do the new syntax with the existing << operator, you’ll get an error, and if the parser doesn’t know the new operator, you’ll get an error. Same difference.
>
> I propose Alternative 2.
>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author