Thanks Thomas, This does indeed make a difference. .sh.level appears to return the current '.' level.
.sh.level == 0 indicates an interactive shell .sh.level == 1 indicates a '. file' .sh.level == 2 indicates a '. file1' with file1 containing '. file2' etc. .sh.level == '' indicates that the *current* file was directly invoked by the shell. (This resets the .sh.level completely) This is useful. Cheers, Henk [email protected]:
My post seems to have been lost. Re-sending ... ________________________________________ From: [email protected] Sent: den 13 december 2011 10:48
To: [email protected] Subject: RE: [ast-users] Is there a simple way for a script to know if it's run as a script (ksh script ) or sourced (. script) ? Hi Henk, It seems like the parameter .sh.level does exactly what you are looking for, though I don't understand the documentation of it. $ cat u.sh #!/bin/ksh if [[ ${.sh.level} ]] then print SOURCED else print CALLED fi $ ./u.sh CALLED $ . ./u.sh SOURCED $ cat t.sh #!/bin/ksh ./u.sh . ./u.sh $ ./t.sh CALLED SOURCED $ echo ${.sh.version} Version JM 93t+ 2009-05-01 BR Thomas Magnusson
_______________________________________________ ast-users mailing list [email protected] https://mailman.research.att.com/mailman/listinfo/ast-users
