1. 自定义变量
1.1 定义变量
#!/usr/bin/bash ip=115.239.210.27 if ping -c1 $ip &>/dev/null ;then # &>/dev/null: output of ping $ip is null echo "$ip is up." else echo "$ip is down." fi
1.2 输入变量
#!/usr/bin/bash read ip ping -c1 $ip &>/dev/null if [ $? -eq 0 ]; then echo "$ip is up." else echo "$ip is down." fi
1.3 位置变量($1, $2.....)
#!/bin/bash ping -c1 $1 &>/dev/null if [ $? -eq 0 ]; then echo "$1 is up." else echo "$1 is down." fi
2. 环境变量
2.1 export
echo "ip1 is $ip1" echo "ip2 is $ip2"
(ip2 是环境变量)
原文地址:https://www.cnblogs.com/douzujun/p/10361832.html
时间: 2024-10-28 17:27:25