-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_getopt.inc
More file actions
executable file
·61 lines (50 loc) · 1.48 KB
/
_getopt.inc
File metadata and controls
executable file
·61 lines (50 loc) · 1.48 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# BASH ARGUMENT PARSER
# RICK PFAHL <pfahlr@gmail.com>
# 3 NOV 2024
#
# before including set $optstring to something like `ab:g:d: --long alpha,beta,gamma:,delta:`
# representing the options you'll use.
#
# TODO: MAKE IT HANDLE LONG OPTIONS
# Uncomment below to test with sample options:
##optstring="ab:g:d --long alpha,beta:,gamma:,delta:"
# I think I can move something reusable into this file?? idk.
# echo "Testing _getopt"
VALID_ARGS=$(getopt -o "$optstring" -- "$@")
if [[ $? -ne 0 ]]; then
exit 1;
fi
eval set -- "$VALID_ARGS"
# Mostly, I guess this will serve as some form of documentation.
# I swore I read a better way to to do this... and of course forgot, maybe I'm just thinking
# of python. Or was it a zsh thing. fuck. who knows
#
# Anyway, in the file that includes this, you'll need a switch in a while loop
#
# Uncomment rest of file to test with sample options:
while [ : ]; do
case "$1" in
-a | --alpha)
echo "Option -a, --alpha"
shift
;;
-b | --beta)
echo "Option -b, --beta"
echo "There should be a value in these braces: [ $2 ]"
shift;shift;
;;
-g | --gamma)
echo "Option -g, --gamma"
echo "There should be a value in these braces: [ $2 ]"
shift;shift;
;;
-d | --delta)
echo "Option -d, --delta"
echo "There should be a value in these braces: [ $2 ]"
shift;shift;
;;
--) shift;
break
;;
esac
done