0

I have an associative array like that

Array=(["one"]=1 ["two"]=2)

and after a bit of googling to find if "one" is in the array keys, I found that

if [ ${Array["one"]+_} ]; then echo "Found"; else echo "Not Found"; fi

It works as I want but I don't understand the +_ right after Array["one"] What its meaning?

Omar Khalid
  • 324
  • 1
  • 3
  • 15
  • 1
    This is explained in detail at https://wiki.bash-hackers.org/syntax/pe#use_an_alternate_value -- the point of replacing the original value in this use case is that `_` is guaranteed not to be empty, and it's also guaranteed not to word-split into multiple separate words (in which case it could be an invalid argument list for `[` and thus cause an error rather than evaluating to true when used unquoted). – Charles Duffy May 09 '20 at 03:29
  • oh thanks this cleared thing for me – Omar Khalid May 09 '20 at 03:49

0 Answers0