Re: Dotted or executed?
- From: Eric <eric@xxxxxxxxxxxxxxxxx>
- Date: Fri, 12 Dec 2008 19:44:16 +0000
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
.
- References:
- Dotted or executed?
- From: Eric
- Re: Dotted or executed?
- From: Gary Johnson
- Dotted or executed?
- Prev by Date: Re: Removing the first blank line from a set of files
- Next by Date: Re: Removing the first blank line from a set of files
- Previous by thread: Re: Dotted or executed?
- Next by thread: if: Expression syntax help in C shell
- Index(es):
Relevant Pages
|