【发布时间】:2025-12-03 16:00:02
【问题描述】:
我正在运行这个脚本
#!/bin/bash
if [ $# != 2 ]
then
echo argument one must be the site number
echo argument two must be the vlan
fi
site=$1
vlan=$2
deviceNum=1
while read MACLine
do
echo arp -s 10.${site}.${vlan}.${deviceNum} "${MACLine}" temp
deviceNum=`expr $deviceNum + 1`
done < MAC.txt
我用这个作为输入
AC:CC:8E:0A:EF:67
AC:CC:8E:0B:AE:4B
AC:CC:8E:0B:CF:17
00:40:8C:FC:6D:86
00:40:8C:FA:61:B1
AC:CC:8E:0F:B1:C3
AC:CC:8E:0B:E5:2B
AC:CC:8E:0F:B1:D7
AC:CC:8E:0F:B1:DF
我收到这个奇怪的输入...当我将粘贴复制到 Windows 中时(继续阅读)
arp -s 10.10.20.1 AC:CC:8E:0A:EF:67
temp
arp -s 10.10.20.2 AC:CC:8E:0B:AE:4B
temp
arp -s 10.10.20.3 AC:CC:8E:0B:CF:17
temp
arp -s 10.10.20.4 00:40:8C:FC:6D:86
temp
arp -s 10.10.20.5 00:40:8C:FA:61:B1
temp
arp -s 10.10.20.6 AC:CC:8E:0F:B1:C3
temp
arp -s 10.10.20.7 AC:CC:8E:0B:E5:2B
temp
arp -s 10.10.20.8 AC:CC:8E:0F:B1:D7
temp
arp -s 10.10.20.9 AC:CC:8E:0F:B1:DF
temp
但是,在 Ubuntu shell 中,我看到以下内容
temps 10.10.20.1 AC:CC:8E:0A:EF:67
temps 10.10.20.2 AC:CC:8E:0B:AE:4B
temps 10.10.20.3 AC:CC:8E:0B:CF:17
temps 10.10.20.4 00:40:8C:FC:6D:86
temps 10.10.20.5 00:40:8C:FA:61:B1
temps 10.10.20.6 AC:CC:8E:0F:B1:C3
temps 10.10.20.7 AC:CC:8E:0B:E5:2B
temps 10.10.20.8 AC:CC:8E:0F:B1:D7
temps 10.10.20.9 AC:CC:8E:0F:B1:DF
这种疯狂的方法是什么?
注意:这与冒号有关。如果您将 MAC 地址替换为“hello...hello...hello”之类的内容,它会按预期工作
【问题讨论】:
-
将你的脚本粘贴到shellcheck.net 那里你可以看到你有一些[不是决定性但重要的]警告
-
@fedorqui 我做了它建议的更正,但是,正如你自己所说的那样,他们没有解决问题
-
@Mr.Llama 你说得对,是dos格式的输入文件
标签: bash shell ubuntu for-loop