bug-bash
[Top][All Lists]
Advanced

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

Re: Bad substitution breaks conditional statement


From: Chris Elvidge
Subject: Re: Bad substitution breaks conditional statement
Date: Mon, 12 Oct 2020 12:25:17 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 Lightning/5.4

On 12/10/2020 06:23 am, Martin Schulte wrote:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -fdebug-prefix-map=/build/bash-2bxm7h/bash-5.0=. 
-fstack-protector-strong -Wformat -Werror=format-security -Wall 
-Wno-parentheses -Wno-format-sec$
uname output: Linux t1 4.19.0-10-amd64 #1 SMP Debian 4.19.132-1 (2020-07-24) 
x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.0
Patch Level: 3
Release Status: release

Description:

It looks as if a bad substitution detected inside a case of if continues the script flow 
immediately after the conditional statement skipping the remaining statements inside the 
conditional. Please take a look into section "Repeat-By:".

I detected this when running a script containing "${OPTARG@Q}" with a bash 
4.1.5 where @Q is not yet supported - the script continued to run in a bad manner so this 
bug might cause real troubles...

Repeat-By:

schulte@t1:~$ cat bad_substitutions_breaks_conditional
#!/bin/bash

x=y
case $x in
   y)
     echo "x has value ${x@q} - stop now!"
     exit 1;;
esac

echo "running"

if [[ $x == y ]]; then
   echo "x has value ${x@q} - stop now!"
   exit 1
fi

echo "still running"

echo "x has value ${x@q} - stop now!"
exit 1

echo "and running"
schulte@t1:~$ ./bad_substitutions_breaks_conditional
./bad_substitutions_breaks_conditional: line 6: x has value ${x@q} - stop now!: 
bad substitution
running
./bad_substitutions_breaks_conditional: line 11: x has value ${x@q} - stop 
now!: bad substitution
still running
./bad_substitutions_breaks_conditional: line 15: x has value ${x@q} - stop 
now!: bad substitution



Surely if you're using a construct that only exists in version X, it's up to you to check if version X-1 is being used and throw an error there. Isn't that what $BASH_VERSION / $BASH_VERSINFO is for?

--
Chris Elvidge
England




reply via email to

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