.BAT等效于MAC

问题描述:

我已创建一个.bat文件,然后我将其转换为.exe以编辑Windows系统上的hosts文件。我正在接受一个shell脚本。.BAT等效于MAC

我的.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 

我曾尝试以下http://tldp.org/LDP/abs/html/dosbatch.html但没有成功。

+0

虽然你在暗指脚本文件,但这更多的是shell/OS问题,属于[su]。如果您在实际编写脚本时遇到问题,则该网站将是适当的。 – 2014-11-14 15:12:10

+0

我在编写脚本时遇到了问题,我不知道如何使用或使用哪种脚本语言。谢谢。 – 2014-11-14 15:20:29

那么MacOS是一个基于Unix的系统,所以你可以使用任何shell命令。请在Internet上查找“如何使用Bash脚本”或“Sh Script”

+0

感谢您的有用信息! – 2014-11-14 15:19:16

修改主机文件可以在Mac OS X上使用shell脚本完成。如果希望用户能够像执行简单脚本一样执行shell脚本尽可能(即通过双击一个图标),您可能需要考虑使用AppleScript来执行shell脚本。 AppleScript可以存储为可执行文件,以便轻松传递。

+0

非常感谢您的帮助 – 2014-11-14 15:19:43