bash - prevent "dotting" a shell to execute it ( exit in a function killing the terminal vs exiting the shell ) -
this question has answer here:
- how detect if script being sourced 14 answers
 
if launching script exit statement in it, have launch child process.
if launch inside current shell of started terminal session (using . ./<scriptname> exit close main shell, 1 started along terminal session.
die () {   echo "error: $*. aborting." >&2   exit 1 }  [ -s "$1" ] || die "empty file"  echo "this should not reached if $1 not nonempty file"   i aware of situation. write prevent shell being run way:
. shell.ksh params   if run way should error out message. how done? thanks
per the excellent answer related question given dennis williamson:
#!/bin/ksh  if [ "$_" != "$0" ];   echo "this script may not sourced" >&2   return fi  : ...do other things here...      
Comments
Post a Comment