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

Re: bad math expression: illegal character: "



Hi Artur,


> On Jun 5, 2020, at 2:18 PM, Artur Renault <Artur.Renault@xxxxxxxxxxxxx>
> wrote:
> 
> Hello zsh maintainers,
> 
> I ran into an issue with running a sourced script on zsh.
> 
> It’s a simple repro. Take the script repro.sh:
> 
> while (( "$#" )); do
> echo $1
> shift
> done
> 
> Running this with source gives me the following error:
> [~] source repro.sh                                                                                            18:15:53
> repro.sh:1: bad math expression: illegal character: "
> 
> The same script works fine on bash:
> [~] bash -c "source repro.sh hello"                                                                            18:17:23
> hello
> 
> Anyone know what the issue could be here?

For what it's worth, dash also rejects this. I assume that it and
zsh are just more strict about what constitutes a math expression.

I can't opine on which interpretation is "better", but you could
avoid the problem by removing the double quotes. Word splitting and
pathname generation are not performed inside ((...)) or $((...)).

vq


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