5

Strange behaviour of uninitialized arrays and unset arrays

view full story
linux-howto

http://unix.stackexchange.com – I'm writing a script and I discovered some unexpected behaviour of uninitialized and unset array variables that I do not understand. First of all, the length: giacomo@jack-laptop:~$ echo ${#notset[@]} 0 giacomo@jack-laptop:~$ uninitialized= giacomo@jack-laptop:~$ echo ${#uninitialized[@]} 1 Why is the uninitialized length 1? Shouldn't it be zero? Is it because a null variable is considered an array of one null element? This fact leads to some problems. For example suppose I want to create an array, and insert a certain number of things based on the user command line arguments. I thought I (HowTos)