I have create a .bat file which I then converted to .exe to edit the hosts file on Windows systems. I was to conver to a shell script.
My .bat script is
@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
I have tried following http://tldp.org/LDP/abs/html/dosbatch.html but with no success.
Modifying the host file can be done using a shell script on Mac OS X. If you want users to be able to execute the shell script as easy as possible (i.e. by double-clicking an icon), you might want to look into executing the shell script using AppleScript. The AppleScript can be stored as an executable for easily passing it around.