bug-bash
[Top][All Lists]
Advanced

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

Bug in syntax checking causes unintended running of a function


From: David Maas
Subject: Bug in syntax checking causes unintended running of a function
Date: Mon, 18 Apr 2016 12:52:09 -0700

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: `}'

Attachment: test-file.sh
Description: Bourne shell script


reply via email to

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