[NTLUG:Discuss] run a program without ./
Steve Baker
sjbaker1 at airmail.net
Fri Jul 21 00:13:56 CDT 2000
m m wrote:
>
> Hi all:
> I have some questions:
>
> 1. when I try to run a program, some of then need start with "./" and some
> of them are not? how do I set all progrms can run without "./"?
This is all down to your 'path' shell variable.
Type this:
echo $PATH
When I do that, I see:
/usr/local:/usr/local/bin:/usr/local:/usr/local/bin:/opt/kde/bin:/sbin:/bin:/usr/sbin:
/usr/bin:/usr/X11R6/bin:/usr/lib/pgsql/bin:/u/steve/bin:/u/steve/scripts:/usr/demos/bin
...this is the list of places where your Shell will look for programs to
run...typically it starts with a bunch of system directories - with
some private ones tacked on the end.
If your program is *not* in a directory anywhere on that list - then
Linux won't find it ... unless you type the path to the program yourself.
The "./" thing lets the shell know that you want to run the file in
the current directory as a program.
So, (to take a common example) when you install a source-distributed
program, you are frequently told to type:
./configure
make
...says "Run the file called configure THAT IS IN THE CURRENT DIRECTORY,
then search the PATH to find a program called 'make' and run that".
In this case, that's important - you probably have hundreds of files
called 'configure' on your disk - and you REALLY want to be sure to
run the one that's in the current directory and no other. Putting './'
in front ensures that.
However, 'make' is a system program - and you may not know where it's
installed on your disk - so you leave off the path and let Linux go
and find it for you.
You *can* change that 'PATH' variable to include the current directory if
you really want to.
Try this if you use tcsh or some other csh derivative:
setenv PATH ${PATH}:.
...or if you use BASH:
PATH=${PATH}:.
export PATH
That adds '.' (the current directory) to the colon separated list of directories
where Linux looks. (Don't worry - it'll only stay like that for the current
shell session)
Now, if you type the name of an executable file in the current directory - and
providing that's not already a program somewhere else in your 'PATH' - then
it'll get executed. You won't need to type the './' anymore.
Some people like to have their system set up like this - other people worry
about the safety and security of such a scheme.
If you start to type:
configure
make
...then there is now the risk that you might find some other 'configure'
script somewhere earlier in the PATH list...and there is a slight risk
that there is a program called 'make' in the current directory that
ISN'T the standard system program - but does some horrible damage to
your system or something!
> 2. how do I add a script to init? in ther worlds, I want let ths script
> start each time I boot my system. or tell me which HOWTO should I read.
Well, there are a gazillion such places - but I think the 'officially
blessed' one is:
/etc/rc.d/boot.local
...but it really depends critically when exactly during the startup
sequence you want this to happen.
HOWEVER - Are you sure you *REALLY* want to do that. I suspect
you do not.
99% of the time when new Linux users ask this, they *REALLY* want
the program to run when they log in - NOT during a reboot.
If that's what you *really* want, then if you use 'tcsh' or some
other csh derivitive then there are two possible places:
/etc/csh.login
/etc/csh.cshrc
~/.login
~/.cshrc
The '.login' scripts run when you log in, the '.cshrc' scripts
run whenever a new shell is started up. Be very careful what
you put into '.cshrc' and 'csh.cshrc' because EVERY script you
run will run whatever you put in there. Since quite a few system
programs are shell scripts - you can do significant damage if
you don't know what you are doing!
In both cases, the '/etc/csh.XXXX' file applies to ALL users
on your system and the '.XXXX' file applies only to the user
into whose home directory it's placed.
If you run 'bash' then the file is (erm - I don't use BASH)...
~/.bash_login
...I think...I forget...well, just RTFM. "man bash"
--
Steve Baker HomeEmail: <sjbaker1 at airmail.net>
WorkEmail: <sjbaker at link.com>
HomePage : http://web2.airmail.net/sjbaker1
Projects : http://plib.sourceforge.net
http://tuxaqfh.sourceforge.net
http://tuxkart.sourceforge.net
http://prettypoly.sourceforge.net
More information about the Discuss
mailing list