Why does this Awk command:
iphost="$(ssh root@$machine -x "host $machine | awk '/has address/ { print $4 }'")"
echo $iphost
Display:
g-3.xx.yyy.zz has address 172.16.65.35
Instead of:
172.16.65.35
Why does this Awk command:
iphost="$(ssh root@$machine -x "host $machine | awk '/has address/ { print $4 }'")"
echo $iphost
Display:
g-3.xx.yyy.zz has address 172.16.65.35
Instead of:
172.16.65.35
You should use escape sequence backslash(\) inside awk command as below. Since you use the command inside double quotes the variables will be resolved before executing. So it will try to understand $4 as a system variable and try to resolve it. If you use escape sequence backslash it will retain the $4 to the awk command.
iphost="$(ssh root@$machine -x "host $machine | awk '/has address/ { print \$4 }'")"
echo $iphost