diff --git a/teil27/optional_param.sh b/teil27/optional_param.sh new file mode 100755 index 0000000..aa8b0d8 --- /dev/null +++ b/teil27/optional_param.sh @@ -0,0 +1,55 @@ +#! /usr/bin/bash + +help=0 +verbose=0 +level="" + + +# parsing the valid arguments +VALID_ARGS=$(getopt -o hvl:: --long help,verbose,level:: -- "$@") +if [[ $? -ne 0 ]]; then + exit 1; +fi + +eval set -- "$VALID_ARGS" +print_params() { + count=0 + for var in "$@" + do + echo "Param ${count}: ${var}" + count=$((${count} + 1)) + done +} + + +print_params "$@" +echo "VALID_ARGS=${VALID_ARGS}" +eval set -- "$VALID_ARGS" +print_params "$@" + +while [ : ]; do + case "${1}" in + -h | --help) + help=1 + shift + ;; + -v | --verbose) + verbose=1 + shift + ;; + -l | --level) + level="${2}" + shift 2 + ;; + --) shift; + break + ;; + *) echo "unbekannter Parameter ${1}" + exit 1 + esac +done + +echo "help=${help}" +echo "verbose=${verbose}" +echo "level=${level}" + diff --git a/teil28/.bash_func b/teil28/.bash_func new file mode 100644 index 0000000..57d8b93 --- /dev/null +++ b/teil28/.bash_func @@ -0,0 +1,46 @@ +function extract () { + file_type=$(file -b ${1}) + file_type=${file_type%%,*} + + if [ -f ${1} ] ; then + case ${file_type} in + "bzip2 compressed data") + tar xjvf "${1}" + ;; + "gzip compressed data") + gunzip "${1}" + ;; + "XZ compressed data") + xz -d "${1}" + ;; + "bzip2 compressed data") + bzip2 -d "${1}" + ;; + "RAR archive data") + unrar2dir "${1}" + ;; + "POSIX tar archive (GNU)") + tar xf "${1}" + ;; + "Zip archive data") + unzip "${1}" + ;; + "compress'd data 16 bits") + uncompress "${1}" + ;; + "7-zip archive data") + 7z x "${1}" + ;; + "Zstandard compressed data"*) + zstd -d "${1}" + ;; + *) + echo "'$1' cannot be extracted via extract()" + ;; + esac + else + echo "'${1}' not found." + exit 1 + fi +} + diff --git a/teil28/.gitignore b/teil28/.gitignore new file mode 100644 index 0000000..95468a4 --- /dev/null +++ b/teil28/.gitignore @@ -0,0 +1,3 @@ +*.tar.gz +*.bz2 +*.zip diff --git a/teil28/automkdir.sh b/teil28/automkdir.sh new file mode 100644 index 0000000..81e777f --- /dev/null +++ b/teil28/automkdir.sh @@ -0,0 +1,9 @@ +#! /usr/bin/bash + +automkdir() { +if mkdir "${1}" ; then + cd "${1}" +fi +} + +