Hi Henk,

# This has to be the first thing run at top of script!

if [ "$_" = "$0" ]
  then : #echo " Script is a subshell"
  else : #echo " Script is being sourced"
fi


Good Luck
-Jon



On Fri, Dec 9, 2011 at 6:50 AM, <[email protected]> wrote:

> I've been working on submitting my scripts to unit tests (a story in
> itself, ask me if you're interested).
>
> This puts some (good) restrictions and challenges on my scripts:
>
> So should all code should be wrapped in functions. (Without functions,
> no units, no unit tests)
>
> But I need a way to determine if a script is being sourced or is
> actually called by the interpreter.
>
> So far the only way I've found requires that the script knows the name
> it is going to be called by.
>
> For the ksh88 shell under Solaris, I found that $LINENO does not
> increment beyond 1 when a file is sourced.
> Alas, this may be considered a bug, as ksh93 does not show this
> behaviour.
>
> Any ideas beyond:
>
> ----- snip -----
> #!/bin/ksh
>  .
>  . function definitions ...
>  .
> myname=script.sh
> [[ ${0##*/} == $myname ]] && main "$@"
> ----- snip -----
>
> Cheers,
> Henk Langeveld
> _______________________________________________
> ast-users mailing list
> [email protected]
> https://mailman.research.att.com/mailman/listinfo/ast-users
>



-- 

-Jon
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to