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
.