If launching a script with an exit
statement in it, you have to launch it as a child process.
If you launch it inside the current shell of started with your terminal session (using . ./<scriptname>
any exit will close the main shell, the one started along your terminal session.
die () {
echo "ERROR: $*. Aborting." >&2
exit 1
}
[ -s "$1" ] || die "empty file"
echo "this should not be reached if $1 is not a nonempty file"
I am aware of this situation. I would like to write something where I prevent the Shell from being run this way:
. shell.ksh params
If someone were to run it this way it should error out with a message. How do I get this done? Thanks