I want to check the type
of the input argument
in bash.
Here is the test function:
my_fun() {
local -A var_map
local -a var_list
local var_string=""
check_type "var_map"
check_type "var_list"
check_type "var_string"
}
check_type() {
local -n test_name="$1"
# How to check the type of "test_name" is a "map", "list", or "string" here?
local type="$(what_command_to_check_type "$test_name")
if [[ "$type" == "-A (map)" ]]
then
echo "this is a map"
elif [[ "$type" == "-a (list)" ]]
then
echo "this is a list"
elif [[ "$type" == "string" ]]
then
echo "this is a string"
fi
}
How to check the type
in the “check_type()
“?