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

Re: here document within a switch fails to parse.



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