我将如何使用 for 循环编写这个 Linux 脚本?我试过了
for i in {1..4}
do
na$1=$(echo $na | cut -d. -f$i);
done
但它没有正确执行。
na=$1;
ba=$2;
tff=255;
na1=$(echo $na | cut -d. -f1);
na2=$(echo $na | cut -d. -f2);
na3=$(echo $na | cut -d. -f3);
na4=$(echo $na | cut -d. -f4);
ba1=$(echo $ba | cut -d. -f1);
ba2=$(echo $ba | cut -d. -f2);
ba3=$(echo $ba | cut -d. -f3);
ba4=$(echo $ba | cut -d. -f4);
oct1=$(expr $ba1 - $na1);
oct2=$(expr $ba2 - $na2);
oct3=$(expr $ba3 - $na3);
oct4=$(expr $ba4 - $na4);
sm1=$(expr $tff - $oct1);
sm2=$(expr $tff - $oct2);
sm3=$(expr $tff - $oct3);
sm4=$(expr $tff - $oct4);
NETADDR=$na1.$na2.$na3.$na4;
BCAST=$ba1.$ba2.$ba3.$ba4;
netmask=$sm1.$sm2.$sm3.$sm4;
echo "sshd: $NETADDR/$netmask";
exit;
我收到错误:
bash: line 15: na1=: command not found