From ce2ca78293793b1cca138ae3737d5607e076a349 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Tue, 22 Jan 2013 13:52:34 +0000 Subject: [PATCH] Finally a POSIX way to check if a function is defined! --- bootstrap-salt-minion.sh | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/bootstrap-salt-minion.sh b/bootstrap-salt-minion.sh index 012eac9..664d79e 100755 --- a/bootstrap-salt-minion.sh +++ b/bootstrap-salt-minion.sh @@ -383,31 +383,9 @@ fi #------------------------------------------------------------------------------- __function_defined() { FUNC_NAME=$1 - d=$(declare -f $FUNCNAME) - if [ "${DISTRO_NAME_L}" = "centos" ]; then - if typeset -f $FUNC_NAME &>/dev/null ; then - echo " * INFO: Found function $FUNC_NAME" - return 0 - fi - - # Try POSIXLY_CORRECT or not - elif test -n "${POSIXLY_CORRECT+yes}"; then - if typeset -f ${FUNC_NAME} >/dev/null 2>&1 ; then - echo " * INFO: Found function $FUNC_NAME" - return 0 - fi - else - # Arch linux seems to fall here - if $( type ${FUNC_NAME} >/dev/null 2>&1 ) ; then - echo " * INFO: Found function $FUNC_NAME" - return 0 - fi -# if [ "$(grep $FUNC_NAME $(dirname $0)/$(basename $0))x" != "x" ]; then -# # This is really ugly and counter producing but it was, so far, the -# # only way we could have a POSIX compliant method to find if a function -# # is defined within this script. -# echo " * INFO: Found function $FUNC_NAME" -# return 0 + if [ "$(command -v $FUNC_NAME)x" != "x" ]; then + echo " * INFO: Found function $FUNC_NAME" + return 0 fi echo " * INFO: $FUNC_NAME not found...." return 1