bug-bash
[Top][All Lists]
Advanced

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

set -u not working as expected


From: Kristof Burek
Subject: set -u not working as expected
Date: Sat, 1 Aug 2020 19:48:26 +0100

Configuration Information [Automatically generated, do not change]:
Machine: arm
OS: linux-gnueabihf
Compiler: gcc
Compilation CFLAGS: -g -O2 -fdebug-prefix-map=/build/bash-kjgNqe/bash-5.0=.
-fstack-protector-strong -Wformat -Werror=format-security -Wall
-Wno-parentheses -Wno-format-security
uname output: Linux rpi-m4b-1 4.19.118-v7l+ #1311 SMP Mon Apr 27 14:26:42
BST 2020 armv7l GNU/Linux
Machine Type: arm-unknown-linux-gnueabihf

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

(Machine is a Raspberry Pi running Raspbian "Buster")

Description:
        After set -u in a script: when x has not yet been bound to a value, 
        I would expect the statements x+='x' and x+=('x') to cause Bash to
        report an error and exit the script.  But it does not.


Repeat-By:
        ... executing the Bash script below;  I would expect it to fail at
line
        7, but it fails at line 12.  Once line 11 is uncommented, it should
        fail at line 15, but does not.  It then fails at line 18 as
expected.

        This demonstrates that set -u is not working as I understand is
        intended.

        (The line below is line 1 of the script)
          #!/bin/bash

          ## does set -u work with +=?  should but apparently doesn't
          #  (but works with let +=)

          set -u  # Bash complains and exits on first use of an unbound name

          s+='t' # Line 8 - Bash should fail here
          echo "\$s=\"${s}\"."

          #t=''
          t=${t}'t' # Line 12, Bash fails until line 11 loses its starting #
          echo "\$t=\"${t}\"."

          u+=('t') # Line 15, Bash should fail here
          declare -p u

          let v+=1 # Line 18, Once line 11 is uncommented, Bash fails here

          #

        When this issue is fixed, I dare say a few perfectly working scripts
        will fall over, but I hope not too many of mine.

        Your work is heartily appreciated;  MANY THANKS!

        Kindest regards and stay safe

        Kristof Burek

P.S.
        (If of interest, This bug also manifests with the following machine
        /config)
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu'
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL
-DHAVE_CONFIG_H   -I.  -I../. -I.././include -I.././lib  -Wdate-time
-D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector-strong -Wformat
-Werror=format-security -Wall
uname output: Linux vebb01.kalvr.me 4.4.0-169-generic #198-Ubuntu SMP Tue
Nov 12 10:38:00 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 4.3
Patch Level: 48
Release Status: release





reply via email to

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