[Novalug] bash weirdness
Chris Snyder
gopher@3wa.org
Fri Apr 9 15:57:23 EDT 2010
Can somebody please explain to me what this bash snippet is doing? Why is my
array data disappearing outside of the 'while'? Bash doesn't have scoping by
default unless you use local or something like that. WTF?!?
thx
Gopher.
--------------------
#!/bin/bash
ls | while read output; do
data[$i]="$output"
let i++
echo "Current array size: " ${#data[*]}
done
echo "Final array size" ${#data[*]}
--------------------
Here's my output:
bash y
Current array size: 1
Current array size: 2
Current array size: 3
Current array size: 4
Current array size: 5
Current array size: 6
Current array size: 7
Current array size: 8
Current array size: 9
Current array size: 10
Current array size: 11
Current array size: 12
Current array size: 13
Current array size: 14
Current array size: 15
Current array size: 16
Current array size: 17
Current array size: 18
Final array size 0
--
gopher@3wa.org
"Evil is, as humans do" - The Misfits
More information about the Novalug
mailing list