Hi folks,

I came accross the `-v` option of the `test` command and wondered how I
would possibly test not only string- and integer- but also array variables
as a whole and in parts.

I thought it should be possible to say:

declare -Ai foobar=([bar]=0)
test -v foobar[foo] && echo true || echo false
# Output: true
test -v foobar[bar] && echo true || echo false
# Output: true

Even quoting doesn't help here except for the opposite results:

test -v "foobar[foo]" && echo true || echo false
# Output: false
test -v "foobar[bar]" && echo true || echo false
# Output: false

Obviously the results should be "false" and "true", respectively.

Apart from arrays everything else works as follows:

test -v a && echo true || echo false
# Output: false
declare a=""
test -v a && echo true || echo false
# Output: true
test -v b && echo true || echo false
# Output: false
declare -i b=0
test -v b && echo true || echo false
# Output: true
test -v c && echo true || echo false
# Output: false
declare -a c=()
test -v c && echo true || echo false
# Output: true

Cheers,
Tim


-- 
--
`~~~~°<
C92A E44E CC19 58E2 FA35 4048 2217 3C6E 0338 83FC

Reply via email to