I want to detect that it is started using sh
like sh ./check.sh
and terminate it with an error.
check.sh
#!/bin/bash
if [ x$BASH_SOURCE = x"" ] ; then
echo please run by $0 or bash $0 instead.
exit 1
fi
echo OK: you are using bash.
$ sh ./check.sh
please run by ./check.sh or bash ./check.sh instead.
$ ./check.sh
OK: you are using bash.
$ bash ./check.sh
OK: you are using bash.
Recommended Posts