macos - mac上主机的shell脚本不起作用
问题描述
我一直在处理一些主机文件,以将本地网络 ips 添加到主机,使我的同事更容易在不记住 ips 的情况下访问我们的内部设备
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
我通知他们把 hosts.sh 文件放在桌面上,然后去终端写
cd Desktop
./hosts.sh
但是它只是说找不到该命令,并将整个脚本粘贴到终端中会将 wiki 添加到主机文件中,而不是其余的
解决方案
推荐阅读
- c# - 正则表达式仅允许包含至少一个字符且没有空格的字母数字
- spring - Spring Security 和 Grails - 为 Heroku 自定义 URL
- javascript - Webpack:如何将类构造函数公开给浏览器的全局命名空间
- git - 通过脚本添加 git webhook
- stdio - 有没有办法覆盖下面代码中的变量
- javascript - 从反应状态对象上的字符串调用函数
- excel - 让 Excel 宏仅填充所需的单元格
- javascript - Chart js, Canvas 是空聚合物项目
- wordpress - 带有 .htaccess 的条件标头适用于 HTML,但不适用于 WordPress
- windows - 通过 azure-pipelines.yml + 脚本设置 Windows 环境变量