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

Re: curiosity with here document.



26.11.2015, 21:38, "Ray Andrews" <rayandrews@xxxxxxxxxxx>:
> I often comment out blocks of code with here-document, and I just found
> this strange thing:
>
>     /test1 ()/
>     /{/
>     / if [[ "$1" = 'howdy' ]];/
>
>     /: <<'COMMENT'/
>     /blah blah
>     COMMENT/
>
>     / then/
>     / echo stranger/
>     / fi/
>     /}/
>
>     /$ test1 no/
>     /stranger/
>
> There's no issue if I put the 'then' above the here-document. How should
> I understand that? It is as if the here-document is hijacking the 'if'
> test and returning true. I'd expect the 'if' to go hunting for it's
> 'then' and if it doesn't find it, then throw and error, but not let the
> here-document interlope. But if this is proper then it's a caution as
> to using these things for commenting.

And when writing such questions do read documentation. The specification for `if` looks like

    if list then list [ elif list then list ] ... [ else list ] fi

and using “list” for *both* `if` condition and `then` block should have given you an answer.



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