In bash 4.2, you can use the -v operator in a conditional expression to check if a variable with the given name is set.
if [[ -v ${1}_ID ]]; then echo "${1}_ID is set" foo=${1}_ID echo "${!foo}" fi
Obtaining a value still requires an indirect extension of the parameter.
In bash 4.3, you can use a named link to make it easier to use.
declare -n param=${1}_ID if [[ -v param ]]; then echo "${1}_ID" echo "$param" fi
( param will behave exactly like the variable it refers to. I don't know if there is a simple way that does not parse the output of declare -p param to get the name of the variable it refers to.)
source share