I want to save the variable name and its contents easily from my script.
Currently :-
LOGFILE=/root/log.txt
TEST=/file/path
echo \"TEST : ${TEST}\" &
You want to use Variable Indirection. Also, don't use the function
keyword, it is not POSIX and also not necessary as long as you have ()
at the end of your function name.
LOGFILE=/root/log.txt
save()
{
echo "$1 : ${!1}" >> ${LOGFILE}
}
TEST=/file/path
save TEST
$ TEST=foo; save(){ echo "$1 : ${!1}"; }; save TEST
TEST : foo