DStevenson <[EMAIL PROTECTED]> wrote:
> On Monday 09 July 2001 00:45, faisal gillani wrote:
> > well i finally wrote my first shell script ... now i
> > want to make it
> > excutable ... i dont want to run it as ./filename
> > i tried to make it excutable with the following
> > command
> >
> > chmod a+x ./filename
> This would make it executable, is it readable by the group who will be 
> executing it?

Probably, since I assume the user who wrote it (Faisal, I assume) is
testing it.

> > is it ok ?
> > if yes then why is it not working
> >
> I guess you mean it is working when you execute it from the directory where 
> it resides. That you currently have to enter the dot slash. That is because 
> the system variable $PATH does not have the parent directory in it, either 

<minor nit - '.' is current dir, not parent dir.  I think you meant 'does not
have the directory that holds your script in it, either as'...>

> explicitly declared or as a relative '.' (a dot = current working directory 
> CWD) 

Also, if you are using a csh-variant, you will need to do 'rehash' to get the
csh-variant to reload its cache of filenames.

> The system does not know where to look for the executable, it tries to find 
> it in the paths, but to no avail. Typing ./program tells the system where it 
> is relative to the CWD.

Sure, but if Faisal (and others ;-) do that, and it STILL does not work
(giving something like 'program not found') then the problem is probably
that the shebang line is wrong.


Huh???  What's that??    Right here:

#!/bin/bash

that's the shebang line.  (the first line of any script should have the
old 'shebang' (hash bang) to tell the system where the interpreter is)
And if your path to your interpreter is wrong, you'll get the really
helpful 'file not found' (or something like that) error.

So, make sure you've got a shebang, and it points to the right place..


ON a slightly different note, and in response to the comments about having
'.' in your path:

Having '.' in your path is a bad thing, from a security point of view.
(If you are root, then its more than just a bad thing, its an open
invitation to be hacked).  Its ESPECIALLY bad if its not the LAST thing
in your path.

WHy?  because if its before /bin, and you change directory into a place
where someone has installed a trojan program that also happens to live
in /bin, and you try to run that program (or script, etc) from /bin, you
get instead the trojan, and you've just been compromised....

Gotta run, sorry this is so 'short' ;-)

rc


Rusty E. Carruth       Email:     [EMAIL PROTECTED] or [EMAIL PROTECTED]
Voice: (480) 345-3621  SnailMail: Schlumberger ATE                   ___
FAX:   (480) 345-8793             7855 S. River Parkway, Suite 116   \e/
Ham: N7IKQ @ 146.82+,pl 162.2     Tempe, AZ 85284-1825                V
ICBM: 33 20' 44"N   111 53' 47"W  http://tuxedo.org/~esr/ecsl/index.html

Reply via email to