bug-bash
[Top][All Lists]
Advanced

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

Re: Bug in syntax checking causes unintended running of a function


From: konsolebox
Subject: Re: Bug in syntax checking causes unintended running of a function
Date: Tue, 19 Apr 2016 11:38:07 +0800

On Tue, Apr 19, 2016 at 3:52 AM, David Maas <address@hidden> wrote:
> Hi! I found a bug in bash, I've checked versions 4.1 (centos 6.7), 4.2
> (centos 7.2), and 4.3.30 (from the ftp site). The bug is that if you do a
> double parenthesis math thing with the wrong syntax, the script runs the
> function during what I assume is syntax checking. Demonstration script is
> attached.
>
>
> -------------- Script --------------
>
> #!/bin/bash
> #Should be avg=((avg+6))
>
> function neverrunme
> {
>     avg=0
>     avg=(($avg+6))
>     echo -n "This function was never called. Bash version:"
>     /bin/bash --version | head -1
> }
>
> echo "Welcome to this demonstration."
>
> -------------- Output --------------
>
>
> address@hidden ~]$ ./test-file.sh
> ./test-file.sh: line 7: syntax error near unexpected token `('
> ./test-file.sh: line 7: `    avg=(($avg+6))'
> This function was never called. Bash version:GNU bash, version
> 4.2.46(1)-release (x86_64-redhat-linux-gnu)
> ./test-file.sh: line 10: syntax error near unexpected token `}'
> ./test-file.sh: line 10: `}'

It didn't run the function. The function-syntax-checking scope simply
ended in `avg=(($avg+6))`.



reply via email to

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