src/eprefix-activate: better way to detect if the script is sourced

Signed-off-by: Maciej Barć <xgqt@protonmail.com>
This commit is contained in:
Maciej Barć 2020-12-21 23:51:51 +01:00
parent 462dab713e
commit da429430ad
No known key found for this signature in database
GPG Key ID: 031C9FE65BED714A
1 changed files with 11 additions and 6 deletions

View File

@ -72,12 +72,17 @@ eprefix_world() {
# >>> Checks
# Exit if script is not sourced
if [[ "${0}" != *sh ]]
then
echo "Don't run this script"
echo "Source it instead"
exit 1
fi
case ${-} in
*i* )
:
;;
* )
echo "${eprefix_bad} Error: not a login shell"
echo "${eprefix_bad} Run: source ${0}"
echo ">>> Exiting the shell"
exit 1
;;
esac
# Exit if eprefix does not exist
if [ ! -d "${EPREFIX}" ]