我已創建一個.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但沒有成功。
雖然你在暗指腳本文件,但這更多的是shell/OS問題,屬於[su]。如果您在實際編寫腳本時遇到問題,則該網站將是適當的。 – 2014-11-14 15:12:10
我在編寫腳本時遇到了問題,我不知道如何使用或使用哪種腳本語言。謝謝。 – 2014-11-14 15:20:29