How can you keep yourself from running some of the commands in a directory in your ? For example, I use several different computers. I read and store my on just one computer - on that host, I want to use all the email commands. On the other computers, I want to be able to use mail-sending commands - but I don't want the mail-reading commands to work on my account there.
You might work on a project with shared filesystems where some commands will only work on certain computers. How can you stop the commands from being run accidentally on computers where they shouldn't be? There's a beginner on the system who shouldn't be running dangerous commands. How can you stop him from using just those commands?
You could makefor those commands that just echo a message to the terminal. But having tens or hundreds of aliases like that can be a real headache.
Here's how I solved my problem.
On all of my computers, the commands for the email system I use (called
MH) are stored in the directory /usr/local/mh.
I make a directory named no_run.
hostname that has short
The scripts have the same names as the the commands in
/usr/local/mh that I don't want
On the computers where I don't want to run those commands, I put the
hostname directory before the /usr/local/mh
directory in my path:
switch (`uname -n`) case cruncher: set path=( ... ~/no_run.cruncher /usr/local/mh ... ) ...
(Acan help, too.) When I try to use a command that I shouldn't, the shell will find the shell script in the no_run directory before the real command in the mh directory. The shell script rings the bell, prints a message with its own name and the name of the computer to use, then quits:
incbeep... You can't run inc here. Use sunspot.
To save disk space, the shell scripts in the no_run directory are allto each other:
ls -li no_run.cruncher... 270156 -rwxr-xr-x 31 jerry 82 Jun 12 09:10 inc 270156 -rwxr-xr-x 31 jerry 82 Jun 12 09:10 mark 270156 -rwxr-xr-x 31 jerry 82 Jun 12 09:10 msgchk ...a total of 31 links...
The script uses the commandto include its (current) command name with the warning message:
#! /bin/sh echo "\007You can't run `basename $0` here. Use sunspot." 1>&2 exit 1
\007 rings the bell on my version of echo; your version
might need a
\a or a
shows a similar script.