下面是一个示例脚本,它使用 ifconfig
命令获取系统的 IP 地址:
#!/bin/bash
# Store the output of the ifconfig command in a variable
ifconfig_output=$(ifconfig)
# Extract the IP address using grep and cut
ip_address=$(echo "$ifconfig_output" | grep 'inet' | cut -d ' ' -f 10)
# Print the IP address
echo "IP address: $ip_address"