help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: is a for .. do list newline sensitive ?


From: Lawrence Velázquez
Subject: Re: is a for .. do list newline sensitive ?
Date: Sat, 14 Oct 2023 14:32:46 -0400
User-agent: Cyrus-JMAP/3.9.0-alpha0-1019-ged83ad8595-fm-20231002.001-ged83ad85

On Sat, Oct 14, 2023, at 9:25 AM, alex xmb sw ratchev wrote:
> i have along other code ..
>
>   for p in
> "$f"{,.d}
>   do
>  [[ -e "$f" ]] &&
> mv "$p"{,."$r"}
>  done
>
> it said
>
> mah: line 13: syntax error near unexpected token `"$f"{,.d}'
> mah: line 13: `"$f"{,.d}'
>
> i changed to not so many newlines , .. worked ..
>
> i report , cause i dunno if its some bug .. that err msg

It is not a bug; if present, the word list may not be preceded by
a line break.  This is required by the POSIX grammar [*] and
consistent with other shells:

        % cat example.sh 
        for x in
                foo bar baz
        do
                :
        done
        % bash ./example.sh 
        ./example.sh: line 2: syntax error near unexpected token `foo'
        ./example.sh: line 2: ` foo bar baz'
        % dash ./example.sh 
        ./example.sh: 2: Syntax error: word unexpected (expecting "do")
        % ksh ./example.sh 
        ./example.sh: syntax error at line 2: `foo' unexpected
        % mksh ./example.sh 
        ./example.sh[2]: syntax error: unexpected 'foo'
        % oksh ./example.sh 
        ./example.sh[2]: syntax error: `foo' unexpected
        % yash ./example.sh 
        ./example.sh:2: syntax error: `do' is missing
        ./example.sh:3: syntax error: encountered `do' without a matching 
`for', `while', or `until'
        ./example.sh:3: syntax error: (maybe you missed `done'?)
        % zsh --emulate sh ./example.sh 
        ./example.sh:2: parse error near `foo'


[*]: 
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_10_02


-- 
vq



reply via email to

[Prev in Thread] Current Thread [Next in Thread]