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

Re: [bug] Problem with functions -s (string arg) math function & specific input



2019-08-19 03:00:24 +0200, Sebastian Gniazdowski:
> Hello,
> the contents of the string argument seems to be evaluated in some way
> (while it shouldn't). Reproducing snippet:
> 
> mtest() { print ${#1}; }
> functions -s -M mtest 1 1 mtest
> input=') &>/dev/null'
> (( mtest($input) ))
> 
> Output:
> 0
> zsh: bad math expression: operand expected at `>/dev/null...'
[...]

Expansions are done first, and then the result evaluated as
an arithmetic expression. That's a POSIX requirement (for
$((...)))

So here, you're evaluating the:

mtest() &>/dev/null

arithmetic expression.

Just like in:

a='1] + b[2'
echo $((b[$a]))

you're evaluating the b[1] + b[2] arithmetic expression.

-- 
Stephane



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