Suppose that I have a variable var in bash. I can assign a value to it. For example, I will make it a string:
var="Test"
I want to echo the name of var, not the value held by var. (I can do the latter with echo $var, but I actually want to do the former.)
The answer to this question from SO says to use echo ${!var}, but when I do that I echo just returns a blank line. For example, this bash script
#!/bin/bash
echo "Hi"
var="Test"
echo ${!var}
echo "Bye"
returns this output:
Hi
Bye
with just a blank line between Hi and Bye, instead of var. What am I doing wrong?
I'm running bash 4.1.5(1) on Ubuntu 10.04.4.
echo var?var=Test; Test=SO; echo ${!var}nameofin various programming languages. There are uses for that.