Running the echo and other contents of the function really doesn't seem like the correct behavior. If the function isn't called, then its contents shouldn't be executed.
Hypothetically, what if the author was partway through writing a backup script that removes backed up data? The behavior of bash in this instance could cause a serious problem. - David On Mon, Apr 18, 2016 at 8:38 PM, konsolebox <konsole...@gmail.com <javascript:_e(%7B%7D,'cvml','konsole...@gmail.com');>> wrote: > On Tue, Apr 19, 2016 at 3:52 AM, David Maas <david.m...@gmail.com > <javascript:_e(%7B%7D,'cvml','david.m...@gmail.com');>> 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 -------------- > > > > > > [dm5284@juphub ~]$ ./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))`. >