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

Re: indented heredocs



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