Bash : Funktion um Files zu laden

Funktion um Dateien aus dem Internet zu laden. Prüft ob curl vorhanden ist , wenn nicht wird wget versucht. Wenn gar nichts von beiden gefunden wird wird das Skript beendet.

function get_remote_file () {
        # ------------------------- get_remote_file -------------------------------------------------------------------
        # download an file to local storage
        #
        # need 2 parameters : get_remote_file [URL_TO_FILE] [LOCAL_PATH]
        # -----------------------------------------------------------------------------------------------------------------

        if [[ ! -z "${1}" || ! -z "${2}" ]]; then
                bin_dl=""
                # check Local Path
                if [ ! -d "${2}" ]; then
                        mkdir "${2}"
                fi
                # check bins
                # using command instead of which to be posix comp.
		
		# ------ check curl
                command -v curl >/dev/null 2>&1
                if [ $? -eq 0 ]; then
                        bin_dl="curl -s -O "
                fi

		# ------ check wget
                command -v wget >/dev/null 2>&1
                if [[ ${bin_dl} = "" && $? -eq 0 ]]; then
                        bin_dl="wget -q "
                fi

		# ------ if emtpy curl and wget not found
                if [ ${bin_dl} = "" ]; then
                        echo "need curl or wget for work please install one of them"
                        exit 98
                fi

                # download file
                if [[ "${1}" =~ http:// || "${1}" =~ https:// || "${1}" =~ ftp:// ]]; then
                        # ${1} is an remote file will be downloaded to ${2}
                        cd "${2}" && { ${bin_dl} "${1}" ; cd -; }
                else
                        # ${1} is not an remote file EXIT !
                        exit 98
                fi
        else
                echo "check parameters for function #> get_remote_file"
                exit 9
        fi
}
“Das einzig sichere System müsste ausgeschaltet, in einem versiegelten und von Stahlbeton ummantelten Raum und von bewaffneten Schutztruppen umstellt sein.”
Gene Spafford (Sicherheitsexperte)