-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharguments
More file actions
executable file
·33 lines (30 loc) · 1.06 KB
/
arguments
File metadata and controls
executable file
·33 lines (30 loc) · 1.06 KB
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
#!/bin/sh
# This script is licensed under the unlicense, please view the LICENSE file or go to https://unlicense.org/ for more information
# Basic POSIX shell script which showcases arguments
HELP="Usage: arguments [-hvabcd]
This is a posix shell script to help study and understand commandline arguments
-h help command
-v version info
-a \"string\" first parameter argument (required to exit with 0)
-b b argument
-c c argument
-d \"string\" second parameter argument"
VERSION="1.1"
# getopts syntax is simple, single letter arguments only, : = argument with a parameter
while getopts ":vha:bcd:" opt; do
case "$opt" in
"h") echo "$HELP" # help information from above
exit 1;;
"v") echo "$VERSION" # version information from above
exit 1;;
"a") parameterA="$OPTARG";; # required parameter
"b") echo "argument b";;
"c") echo "argument c";;
"d") parameterD="$OPTARG";; # required parameter
*) echo "$HELP"
exit 1;;
esac
done
[ -z "$parameterA" ] && exit 1
echo "arg a: $parameterA"
[ -z "$parameterD" ] || echo "arg d: $parameterD" && exit