From: Antonio Ospite Date: Tue, 6 Oct 2015 10:26:17 +0000 (+0200) Subject: setenv: check in a more robust way that the script is being sourced X-Git-Url: https://git.ao2.it/android/android-app-development-getting-started.git/commitdiff_plain/b1642210516b6aeb2762d6811506f4fb6d66c24c?ds=sidebyside setenv: check in a more robust way that the script is being sourced Sometimes a leading '-' shows up in $0 for login shells, for example this happens when opening a shell with "sudo -i"; in these cases $0 will look like "-bash" instead of "bash", and the comparison with $(basename $SHELL) fails even if the script is being sourced. Fix this by stripping the leading '-'. --- diff --git a/setenv b/setenv index e5c51a5..b9a1569 100644 --- a/setenv +++ b/setenv @@ -1,6 +1,6 @@ #!/bin/sh -[ "$0" = "$(basename $SHELL)" ] || { echo "This script is meant to be sourced, not executed" 1>&2; exit 1; } +[ "${0#-}" = "$(basename $SHELL)" ] || { echo "This script is meant to be sourced, not executed" 1>&2; exit 1; } export ANDROID_HOME=$HOME/Android/android-sdk-linux export PATH=$PATH:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools