I'm trying to extract FQDN for a CentOS 7.3 host. This is the script I use:
hostname=$(dig +short -x 10.10.10.10)
hostname=${hostname%.}
The reason for the 2nd line is the dig
output returns a dot .
at the end for e.g. abc@def.com.
. And hence the 2nd line to strip the last character i.e .
Is there a way I can do this in one line as a single line command? something like hostname=${$(dig +short -x 10.142.114.44)%.}
. Basically, I'm looking to expand variable within another variable. I tried using ${!..}
but couldn't make it work and ended up with substitution error. I referred this and also this.