diff --git a/tools/bufr_filter b/tools/bufr_filter index 6e34b3168..e631b87a0 100755 --- a/tools/bufr_filter +++ b/tools/bufr_filter @@ -6,6 +6,7 @@ ECCODES_TOOL=codes_bufr_filter result=0 # return code from function ERR_TOOL_NOT_FOUND=666 +the_tool=$ECCODES_TOOL is_emoslib=0 ######################################################### @@ -15,15 +16,12 @@ is_emoslib=0 # sets the global variable 'result' try_tool() { - the_tool=$1 - the_args=$args - if [ -f "${script_dir}/$the_tool" ]; then - ${script_dir}/$the_tool $the_args + ${script_dir}/$the_tool "${@}" result=$? else if command -v $the_tool >/dev/null 2>&1; then - $the_tool $the_args + $the_tool "${@}" result=$? else #echo "Could not find $the_tool. Return error" @@ -36,32 +34,30 @@ try_tool() # Deal with case where no arguments are provided e.g. usage if [ $# -eq 0 ]; then # Give priority to ecCodes over emoslib - try_tool $ECCODES_TOOL + the_tool=$ECCODES_TOOL + try_tool "${@}" if [ $result -eq $ERR_TOOL_NOT_FOUND ]; then - try_tool $EMOSLIB_TOOL + the_tool=$EMOSLIB_TOOL + try_tool "${@}" fi exit 0 fi # Now process arguments. The "-i" switch is specific to emoslib -args="$@" for i in "$@" ; do - case $i in - -i) is_emoslib=1; shift ;; - *) shift ;; - esac + if [ "$i" = "-i" ]; then is_emoslib=1; fi done ######################################################### # set -x if [ $is_emoslib -eq 1 ]; then pkg=emoslib - tool=$EMOSLIB_TOOL - try_tool $tool + the_tool=$EMOSLIB_TOOL + try_tool "${@}" else pkg=ecCodes - tool=$ECCODES_TOOL - try_tool $tool + the_tool=$ECCODES_TOOL + try_tool "${@}" fi if [ $result -eq $ERR_TOOL_NOT_FOUND ]; then echo "ERROR: Could not find the executable: $tool. Aborting!" 2>&1