Shell scripting: check if an array is empty









declare -a array1=()

if [[ ${#array1[@]} -eq 0 ]]; then
    echo "array1 is empty"
fi

array1+=('foo')
echo "array1 has ${#array1[@]} elements"

array1+=('bar')
echo "array1 has ${#array1[@]} elements"





No comments:

Post a Comment