[Novalug] How can script know if it's been 'sourced' rather than 'called'?

Michael Stone mstone at mathom.us
Fri Apr 6 15:11:37 EDT 2007


On Fri, Apr 06, 2007 at 02:52:38PM -0400, Richard Rognlie wrote:
>$ ./test.sh
>SHELL=/bin/bash
>0=./test.sh
>called
>
>$ . ./test.sh
>SHELL=/bin/bash
>0=/bin/bash
>sourced
>
>$ bash test.sh
>SHELL=/bin/bash
>0=test.sh
>called

user's shell is zsh:
% . ./test.sh 
SHELL=/usr/bin/zsh
0=./test.sh
called

user's shell is sh:
$ . ./test.sh
SHELL=/bin/sh
0=sh
called

user's shell is tcsh:
> . test.sh 
SHELL=/usr/bin/tcsh
0=tcsh
if: Expression Syntax.



More information about the Novalug mailing list