Macos .BAT等效于MAC

Macos .BAT等效于MAC,macos,batch-file,hosts,Macos,Batch File,Hosts,我创建了一个.bat文件,然后将其转换为.exe以在Windows系统上编辑主机文件。我要转换成一个shell脚本 我的.bat脚本是 @ECHO off setlocal enabledelayedexpansion ::Create your list of host domains set LIST=(www.google.com) ::Set the ip of the domains you set in the list above set www.google.com=192.16

我创建了一个.bat文件,然后将其转换为.exe以在Windows系统上编辑主机文件。我要转换成一个shell脚本

我的.bat脚本是

@ECHO off
setlocal enabledelayedexpansion
::Create your list of host domains
set LIST=(www.google.com)
::Set the ip of the domains you set in the list above
set www.google.com=192.168.1.1
:: deletes the parentheses from LIST
set _list=%LIST:~1,-1%
::ECHO %WINDIR%\System32\drivers\etc\hosts > tmp.txt
for  %%G in (%_list%) do (
    set  _name=%%G
    set  _value=!%%G!
    SET NEWLINE=^& echo.
    ECHO Carrying out requested modifications to your HOSTS file
    ::strip out this specific line and store in tmp file
    type %WINDIR%\System32\drivers\etc\hosts | findstr /v !_name! > tmp.txt
    ::re-add the line to it
    ECHO %NEWLINE%^!_value! !_name!>>tmp.txt
    ::overwrite host file
    copy /b/v/y tmp.txt %WINDIR%\System32\drivers\etc\hosts
    del tmp.txt
)
ipconfig /flushdns
ECHO.
EXIT

我试过跟随,但没有成功

MacOS是一个基于Unix的系统,因此您可以使用任何shell命令。在internet上查找“How to Bash script”或“Sh script”

可以使用Mac OS X上的shell脚本修改主机文件。如果您希望用户能够尽可能轻松地执行shell脚本(即双击图标),您可能希望使用AppleScript执行shell脚本。AppleScript可以存储为可执行文件,以便轻松传递。

虽然您指的是脚本文件,但这更像是一个shell/OS问题,属于。如果你在实际编写脚本时遇到一些问题,那么这个网站将是合适的。我在编写脚本时遇到了问题,我不知道如何使用脚本或使用什么脚本语言。谢谢