Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: here document within a switch fails to parse.
- X-seq: zsh-users 26336
- From: "Daniel Shahaf" <d.s@xxxxxxxxxxxxxxxxxx>
- To: "Ray Andrews" <rayandrews@xxxxxxxxxxx>, "Zsh Users" <zsh-users@xxxxxxx>
- Subject: Re: here document within a switch fails to parse.
- Date: Wed, 06 Jan 2021 16:20:00 +0000
- Archived-at: <https://zsh.org/users/26336>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-users/2021-01/2bc17f94-91c0-429d-bdea-e39926dc083d%40www.fastmail.com>
- In-reply-to: <db51fbd9-20d4-9a52-1925-1a2c9115771c@eastlink.ca>
- List-id: <zsh-users.zsh.org>
- References: <db51fbd9-20d4-9a52-1925-1a2c9115771c@eastlink.ca>
Ray Andrews wrote on Wed, 06 Jan 2021 15:13 +00:00:
> function test1 ()
> {
> : <<'ENDCOM' # No problems here with either ending #1 or #2
> echo "Bad Idea!" # Some commented code.
> ENDCOM # Ending #1: comment-out one line ok.
> case ${1} in
> n ) echo en ;;
> #: <<'ENDCOM' # This pair: "parse error near `\n'"
> #ENDCOM
> esac
> #ENDCOM # Ending #2: comment-out most of function ok.
> echo "What's goin' on?"
> }
>
> ... So it seemed that a case statement won't tolerate a here document
> within itself. But then there's this, which parses fine:
>
> function test2 ()
> {
> case ${1} in
> n ) echo en ;;
>
> v )
> : <<'ENDCOM' # But this pair works fine.
> echo "BAD!" # Some commented code
> ENDCOM
> echo GOOD!: # Much better.
> ;;
> esac
> }
>
> ... So what am I missing? Sometimes the here document is perfectly
> ignored, other times it creates an error. Looks wrong.
The «;;» token must be followed by a pattern, but in your code, it is
followed by a command («:») (which happens to use a heredocument, yes,
but that's not actually relevant:
$ zsh -fc 'case foo in (bar) ;; pwd; esac'
zsh:1: parse error near `;').
)
> So far I haven't found any comparable errors but this.
Perhaps because many a syntax that look weird are actually valid, but
in any case, here's another place where commands aren't allowed:
repeat foo
bar <<baz
baz
do pwd
done
Cheers,
Daniel
Messages sorted by:
Reverse Date,
Date,
Thread,
Author