PDA

View Full Version : Creating shell scripts


wardo
02-13-2002, 08:42 PM
Hey Folks,

How do you create a shell script?

I've read about a specific script that I would like to implement but I don't know how to compile this in a usable format.

The script in question is

#!/bin/sh

/sbin/ipfw add 0 deny udp from any to any 2222
/sbin/ipfw add 0 deny tcp from any to any 3464
-end clip-

Can someone tell me what I should be creating and where?

Wardo

griffman
02-13-2002, 09:30 PM
It'd be easiest in ~/bin, which you may have to create. You could also put it in /usr/local/bin, but you'll need to do so with root privileges.

Once typed and saved, type chmod 755 script_name" to make it executable, then ./script_name to run it (if you're in the directory where you saved it), or just script_name from elsewhere.

-rob.

pmccann
02-13-2002, 09:40 PM
As Rob said, but with the usual caveat: you won't be able to access the script via its "raw" name --ie, using a simple

% script_name

until you've entered

% rehash

to get the shell to rescan its PATH for executables. The full path to the script (the ./script_name, or more generally something like /Users/you/bin/script_name will work immediately.)

The other option is to simply open another terminal window and close your first one! That invokes a new shell, which runs its own startup scan.

Once you've done either of these two things

% script_name

will work from anywhere.

Cheers,
Paul