Reference to a bash variable whose name contains dot

Since bash.ip is not a valid identifier in bash, the environment string bash.ip=192.168.100.37 is not used to create a shell variable on shell startup.

I would use awk, a standard tool, to extract the value from the environment.

bash_ip=$(awk 'BEGIN {print ENVIRON["bash.ip"]}')

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-'

Tags:

Bash