[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Determinate the directory whithin a script



On Monday 19 June 2006 03:43, Erik Steffl wrote:
> Paolo Pantaleo wrote:
> > 2006/6/18, Paolo Pantaleo <paolopantaleo@gmail.com>:
> >> I have a script in something like
> >>
> >> /media/sda1/backup/script.sh
> >>
> >> since sda1 could be also sda2 or anything, I want to determintate
> >> at run-time what is the directory in which the script is located,
> >> how can I do?
> >>
> >> pwd doesn't work, since I cuold call the script from some other
> >> direcotry
> >>
> >> Thnx
> >> PAolo
> >>
> >> --
> >> if you have a minute to spend please visit my photogrphy site:
> >> http://mypic.co.nr
> >
> > $0 is just the command line... maybe `pwd` + $0 could do the
> > work... but not if the scipt is in the PATH...
> >
> > I can't use udev... but maybe I'll read something about it
> >
> > Well for now I will assume that the script is launched only from
> > the directory in which it is located... it seems the easyer way.
>
>    I don't think you can reliably figure out where the script was
> loaded from, after all it didn't even had to be loaded from file
> system.

I can't find it now, but I did have a routine that would use $0 and 
`pwd` and put them together to find a script's directory.  I didn't 
just concatenate, I also scanned the start of $0 for "../" instances 
and used them to remove the last level or levels of the working 
directory, then concatenated them.  If I can find it, I'll post it.

Hal



Reply to: