NBash

Форк
0
1
#!/usr/bin/env bash
2

3
PATH="..:$PATH"
4

5
# Load argsparse library.
6
. argsparse.sh
7

8
# Miscellaneous other functions. See below.
9

10
argsparse_use_option option1 "An option" value exclude:option2
11
argsparse_use_option option2 "Another option"
12

13
# 
14
printf -v argsparse_usage_description "%s\n" \
15
	"A tutorial script to show other misc argsparse features." \
16
	"Try command lines such as:" \
17
	" $0" \
18
	" $0 -h" \
19
	" $0 --option1 123a" \
20
	" $0 --option2"
21

22
# You can define your own usage function
23
usage() {
24
	printf "Beginning of usage\n"
25
	# Unless you want it to be completely removed, you can still call
26
	# argsparse_usage function to also have auto-generated argsparse
27
	# usage message.
28
	argsparse_usage
29
	printf "End of usage\n"
30
	# And perform your own exit.
31
	exit 16
32
}
33

34
# Allow empty command line
35
argsparse_allow_no_argument yes
36

37
# Command line parsing is done here.
38
argsparse_parse_options "$@"
39

40
if [[ $# -eq 0 ]]
41
then
42
	cat <<'information'
43
Though this script has been called without any parameter, `usage' has
44
not been triggered, due to the "argsparse_allow_no_argument yes"
45
executed a few lines above in the script.
46

47
To obtain the usage message, explicitly add --help on the command line.
48

49
information
50
fi
51

52
# The argsparse_has_option_property function returns with 0 if a named
53
# option has a named property. If the property has a value, it is
54
# printed to standard input. So you can do things like that:
55
if exclusion=$(argsparse_has_option_property option1 exclude)
56
then
57
	printf "The option %s excludes these other options: %s\n" \
58
		option1 "$exclusion"
59
fi
60

61
for option in option1 option2
62
do
63
	if argsparse_has_option_property "$option" value
64
	then
65
		printf "%s has the value property.\n" "$option"
66
	else
67
		printf "%s does not have the value property.\n" "$option"
68
	fi
69
done
70

71
printf "\nOptions reporting:\n"
72
# Simple reporting function.
73
argsparse_report
74
printf "End of argsparse report.\n\n"
75

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.