#!/bin/bash
var=$1
if [[ $var =~ [\`\$\=\/] || $var =~ \[ ]]; then
echo 'no'
exit
fi
declare "$var"=test 2>/dev/null
if [[ ${!var} == 'test' || $1 == 'var' ]]; then
echo 'yes'
else
echo 'no'
fi
This will try to assign the value test to the provided value. If it succeeds (if the value is a valid variable name) it will match the if test and echo yes, else it will echo no.