bash - prevent "dotting" a shell to execute it ( exit in a function killing the terminal vs exiting the shell ) -


this question has answer here:

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

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -