Mac上主机的Shell脚本不起作用

时间:2019-02-01 12:48:58

标签: macos shell terminal sh

我一直在处理一些主机文件,以将本地网络ip添加到主机,从而使我的同事更容易访问我们的内部设备而无需记住ips

Hosts.sh文件

.accessor()

我通知他们将hosts.sh文件放到桌面上,然后去终端写

#!/bin/sh
if grep -Fxq "wiki" /etc/hosts
then
echo 'wiki er allerede tilføjet'
else
echo 'Tilføjer wiki til hosts'
sudo bash -c 'echo -e "192.168.2.13\twiki\n" >> /etc/hosts'
echo 'wiki er blevet tilføjet'
fi
if grep -Fxq "taxatilbus-docs" /etc/hosts
then
echo 'taxatilbus-docs er allerede tilføjet'
else
echo 'Tilføjer taxatilbus-docs til hosts'
sudo bash -c 'echo -e "192.168.2.12\ttaxatilbus-docs\n" >> /etc/hosts'
echo 'wiki er blevet tilføjet'
fi
if grep -Fxq "docucolor" /etc/hosts
then
echo 'docucolor er allerede tilføjet'
else
echo 'Tilføjer docucolor til hosts'
sudo bash -c 'echo -e "192.168.1.7\tdocucolor\n" >> /etc/hosts'
echo 'wiki er blevet tilføjet'
fi
if grep -Fxq "epson" /etc/hosts
then
echo 'epson er allerede tilføjet'
else
echo 'Tilføjer epson til hosts'
sudo bash -c 'echo -e "192.168.1.8\tepson\n" >> /etc/hosts'
echo 'wiki er blevet tilføjet'
fi
if grep -Fxq "brother" /etc/hosts
then
echo 'brother er allerede tilføjet'
else
echo 'Tilføjer brother til hosts'
sudo bash -c 'echo -e "192.168.1.9\tbrother\n" >> /etc/hosts'
echo 'wiki er blevet tilføjet'
fi
if grep -Fxq "mathias-laptop" /etc/hosts
then
echo 'mathias-laptop er allerede tilføjet'
else
echo 'Tilføjer mathias-laptop til hosts'
sudo bash -c 'echo -e "192.168.1.18\tmathias-laptop\n" >> /etc/hosts'
echo 'wiki er blevet tilføjet'
fi
if grep -Fxq "mathias-desktop" /etc/hosts
then
echo 'mathias-desktop er allerede tilføjet'
else
echo 'Tilføjer mathias-desktop til hosts'
sudo bash -c 'echo -e "192.168.1.19\tmathias-desktop\n" >> /etc/hosts'
echo 'wiki er blevet tilføjet'
fi
if grep -Fxq "unifi" /etc/hosts
then
echo 'unifi er allerede tilføjet'
else
echo 'Tilføjer unifi til hosts'
sudo bash -c 'echo -e "192.168.1.11\tunifi\n" >> /etc/hosts'
echo 'wiki er blevet tilføjet'
fi

但是它只是说没有找到该命令,并且将整个脚本粘贴到终端中会将Wiki添加到主机文件,而不是其余文件

0 个答案:

没有答案