Re: shell: full path to currently executed script



"Chris F.A. Johnson" <cfajohnson@xxxxxxxxx> wrote in message news:so3vj3-um8.ln1@xxxxxxxxxxxxxxxxxxxxx
On 2006-05-18, Angel Tsankov wrote:
How can I obtain the full path to the currently executed script?

Why? There is generally no good reason to do that.

However, it is usally in $0.

Well, $0 does not always give the full path. Consider this:
echo 'echo "$0"' > a
chmod 700 a
pwd
stdout: /root
./a
stdout:./a

I need the last command to print /root/a, not ./a

I repeat: why do you need it? There is almost always a better way
to do whatever you really want to do.

I want to copy the files that reside in the same folder as the script to let's say /copy

OK, here's smoe more info:
I'm writing a couple of scripts that perform certain tasks, such as compiling and installing several packages. The scripts could reside on a floppy disk, a cd-rom or a hard drive, i.e. their location is not known in advance. This is because they are meant to be "generic" - end users may store them wherever they find appropriate. At some point the main script must execute one of the other scripts within a chroot'ed environment and here comes the need to copy the latter script to a location that is acessible within the chroot'ed environment. The root of the chroot'ed environment is known in advance. How do I accomplish this?

.



Relevant Pages

  • Re: putenv
    ... and I'd like to use env variables as kind of a global variable that I can pass around to the pythong scripts. ... the calling csh script (or, by extenstion, the environment ... of subsequent python programs that are called by the csh ... csh source command reads commands from the file named as an argument. ...
    (comp.lang.python)
  • Re: rsync (ssh) authorisation weirdness on F18
    ... run as the root user. ... any automatically run scripts: Sometimes scripts don't run in the same ... the full path to any command, rather than just use the command name, and ... hope that it's in the search path of the script's environment. ...
    (Fedora)
  • Re: oSQL - How do I run all .SQL files in a folder by running one batch
    ... the scripts in the folder. ... ECHO Please specify a folder like this: ... you can get the batch file to do that for you: ...
    (microsoft.public.sqlserver.connect)
  • Re: oSQL - How do I run all .SQL files in a folder by running one batch
    ... the scripts in the folder. ... ECHO Please specify a folder like this: ... you can get the batch file to do that for you: ...
    (microsoft.public.sqlserver.tools)
  • Re: oSQL - How do I run all .SQL files in a folder by running one batch
    ... the scripts in the folder. ... ECHO Please specify a folder like this: ... you can get the batch file to do that for you: ...
    (microsoft.public.sqlserver.programming)