ubuntuusers.de

Titel:
lnk_test
Autor:
sugarcube
Datum:
12. Februar 2020 14:53
Aktionen:
Code:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh

ScriptName=$(basename "$0")	# program name

GETOPT="/usr/bin/getopt"

Reihe=false
ReihenName=""
Force=false
ForceFolder=""

# Test if your getopt(1) is this enhanced version or an old version. This generates no output, and sets the error status to 4.
$GETOPT -T
if [ $? -ne 4 ]
then
	echo "Get getopt from http://software.frodo.looijaard.name/getopt or install package util-linux-ng."
	exit 1
fi

echo "Vor Verarbeitung: "$@

Options=$(getopt -u -o nF:R: --longoptions force:,reihe: --name "$ScriptName" -- "$@")

[ $? -eq 0 ] || { 
	echo "Falsche Option angegeben"
	exit 1
}

eval set -- "$Options"

echo "Nach Getopt:     "$Options

while true; do
	case "$1" in
		-F | --force ) 
			Force=true; ForceFolder="$2"; shift 2 ;;
		-n | --new | --neu ) 
			IsNew=true; shift ;;
		-R | --reihe ) Reihe=true; 
			ReihenName="$2"; shift 2;;
		-- ) 	shift; break;;
		* ) 
			echo "Falscher Parameter: $1"; break ;;
	esac
done

echo "Neu: $IsNew\nForce: $Force\nForceFolder: $ForceFolder\nReihe: $Reihe\nReihenName: $ReihenName\n\$1: $1\n"