So after fighting with zsh for a bit, it seems there is never, ever, a 0 element in zsh arrays. All arrays start populating at element 1 i.e $array[1]

Here is some example code to help ya populate and pilfer through an array of elements if its got at least one element:

# the following ssh command will return location of each loaded key. for this example, we only have one key loaded.
array_of_lines=("${(@f)$(ssh-add -L | awk -F " " '{print $3}')}")

# Adding an element
array_of_lines+=( this_is_weird )

# Listing out the elements
echo "0 - ${array_of_lines[0]}" ## should be empty  
echo "1 - ${array_of_lines[1]}" ## will display our first element (in this case, we'll only have one)  
echo "2 - ${array_of_lines[2]}" ## will be "this_is_weird"

if [ ${array_of_lines[1]} ]; then  
    for k in ${array_of_lines[@]}; do echo $k; done
    echo "array is not populated"
Blog Logo

Mario Loria




Because gets old after a while.

Back to Overview