Tutorial Dateien.

This commit is contained in:
2026-04-05 12:23:06 +02:00
parent 01372ed6dd
commit 23d29820b4
4 changed files with 113 additions and 0 deletions

55
teil27/optional_param.sh Executable file
View File

@@ -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}"

46
teil28/.bash_func Normal file
View File

@@ -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
}

3
teil28/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
*.tar.gz
*.bz2
*.zip

9
teil28/automkdir.sh Normal file
View File

@@ -0,0 +1,9 @@
#! /usr/bin/bash
automkdir() {
if mkdir "${1}" ; then
cd "${1}"
fi
}