get list of functions in bash script…look for those in argv


# Get function list as array
funcs=($(declare -F -p | cut -d " " -f 3))

# parse out functions and non-functions
i=1
declare -a cmdargs
declare -a otherargs
for var in "$@"; do
    if [[ " ${funcs[@]} " =~ " ${var} " ]]; then
        cmdargs[i]=${var}
    else
        otherargs[i]=${var}
    fi

    ((i++))
done

echo ${cmdarg[*]}
echo ${otherargs[*]}

Leave a Reply

Your email address will not be published. Required fields are marked *