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../bash -I../bash/include -I../bash/lib -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -Wall uname output: Linux moriarty 3.2.0-58-generic #88-Ubuntu SMP Tue Dec 3 17:37:58 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux Machine Type: x86_64-pc-linux-gnu
Bash Version: 4.2 Patch Level: 25 Release Status: release Description: Variables can be automatically cast from string to array. However when cast from array to string, the cast silently fails. Repeat-By: Demonstraction script: #------------- SCRIPT START --------------- #!/bin/bash function demonstrate_fail() { local something something="" # setting something to a string declare -p something something=(hello world now) # setting something to an array declare -p something something="" # setting something to a string declare -p something # UNEXPECTED BEHAVIOUR : something is still an array something=1 # setting something to an integer declare -p something # UNEXPECTED BEHAVIOUR : first array element is updated } demonstrate_fail #------------- SCRIPT END --------------- Fix: Using unset seems only workaround.