vendredi 29 janvier 2021

Check if array is empty in bash [closed]

I am trying to see if an array is empty in bash

key=[]
key1=["2014"]

I have tried following ways:

[[ -z "$key" ]] && echo "empty" || echo "not Empty" 
[[ -z "$key1" ]] && echo "empty" || echo "not Empty"

Both return 'not Empty'

[[ $key==[] ]] && echo "empty" || echo "not Empty"
[[ $key1==[] ]] && echo "empty" || echo "not Empty"

Both return 'empty'.

Aucun commentaire:

Enregistrer un commentaire