Suppose that you have a function with a lot of options and that you decide to store their value dynamically:
#!/bin/bash
fun() {
local OPTIND __option
while getopts ":$(printf '%s:' {a..z} {A..Z})" __option
do
case $__option in
[[:alpha:]])
# ...
local "__$__option=$OPTARG"
esac
done
# here you might get a conflict with external variables:
[[ ${__a:+1} ]] && echo "option a is set"
[[ ${__b:+1} ]] && echo "option b is set"
# etc...
[[ ${__Z:+1} ]] && echo "option Z is set"
}
Is there a way to check if a variable was defined locally?