I have a bash variable: agent1.ip with 192.168.100.137 as its value. When I refer to it in echo like this:
echo $agent1.ip
the result is:
.ip
How can I access the value?
UPDATE: my variables are:

Bash itself doesn't understand variable names with dots in them, but that doesn't mean you can't have such a variable in your environment. Here's an example of how to set it and get it all in one:
env 'agent1.ip=192.168.100.137' bash -c 'env | grep ^agent1\\.ip= | cut -d= -f2-'
The cleanest solution is:
echo path.data | awk '{print ENVIRON[$1]}'
ENVIRON variable, more here , here and here and here. I guess it's not a duplicate of the other answer in that: a) this answer is "shorter" and b) does something different (echos, vs assigns)Try this:
export myval=`env | grep agent1.port | awk -F'=' '{print $2}'`;echo $myval
. in grep means "any character," so this will behave badly if there is e.g. agent1Sport. Likewise flagent1.port or blagent1Sportier. See my answer for a more exact expression.For accessing the environment variable in a readable way, I'd make a shell function of it:
getenv() {
awk 'BEGIN {print ENVIRON[ARGV[1]]}' "$1";
}
You can then use it as
$ getenv agent1.ip
192.168.100.137
$ myvar=$(getenv agent1.ip)
$ echo "$myvar"
192.168.100.137
Differences with the accepted answer are:
grep and cut work on lines)awk) instead of 3 (env, grep, cut) in a pipeline (which also has to set up i/o buffers)There is also another question about Exporting a variable with dot (.) in it.
Short answer: you can't, but you needn't, except for calling another executable. In that case use env.
.in the variable name in the first place?bash.ip=192.168.100.137is a perfectly valid string to include in the environment. It's just not a string whichbashcan automatically turn into a variable.