[root@AlexWong /]# hostname -I | awk -F " " '{printf $1}'
192.168.0.16
脚本
[root@AlexWong mnt]# cat test.sh
#!/bin/bash
IP=$(hostname -I | awk -F " " '{printf $1}')
echo $IP
[root@AlexWong mnt]# sh test.sh
192.168.0.16
[root@AlexWong /]# hostname -I | awk -F " " '{printf $1}'
192.168.0.16
脚本
[root@AlexWong mnt]# cat test.sh
#!/bin/bash
IP=$(hostname -I | awk -F " " '{printf $1}')
echo $IP
[root@AlexWong mnt]# sh test.sh
192.168.0.16