Re: Dotted or executed?



On 2008-12-12, Gary Johnson <garyjohn@xxxxxxxxxx> wrote:


Eric <eric@xxxxxxxxxxxxxxxxx> wrote:
How can I tell, from within a script, whether it is being run as

myscript

or

. myscript

One way would be to test the value of $0. If it ends in "myscript",
your script was run as "myscript". If your script was sourced, the
value of $0 will be the name of your shell.

As an example, you could put something like this in your script:

if [ "${0##*/}" = "myscript" ]
then
echo "Running as a sub-shell"
else
echo "Being sourced"
fi


Thankyou! I can use that one way or another. Should have thought of it
myself really - I blame old age.

E
.



Relevant Pages

  • Re: Fehlerbehandlung
    ... > Das eigentliche script wird durch das Plugin vom Server geladen (d.h. ... denn `myScript' existiert ja; ... Was auf unsaubere Programmierung hindeutet. ... > function objMyScript() { ...
    (de.comp.lang.javascript)
  • Re: how to run python-script from the python promt? [absolute newbie]
    ... interactive mode prompt ... You can make the code in your script available to the interpreter by typing ... import myscript ...
    (comp.lang.python)
  • Reg ridiculously long path truncated
    ... I am running a script on SUN SOLARIS machines. ... under some conditions scripts calls itself recursively. ... When I am running the myscript "rarely" I am getting ... send current PATH to remote session (since user may include his/her ...
    (comp.unix.shell)
  • Re: Command line parameter problem in scripts ?
    ... Lets say the name of the script is myscript. ... echo Argument 1 is $1. ... the first file and then stops. ...
    (Fedora)
  • Re: Run Cron Job every 2 minutes interval
    ... # Script named "myScript" ... perform my script functions ... ... Threr is a mistake or limitation in above method, ...
    (comp.unix.solaris)