summaryrefslogtreecommitdiff
path: root/How to properly do options in a bash script with getopt!.md
diff options
context:
space:
mode:
authorJasper Ras <jras@hostnet.nl>2025-04-15 19:44:48 +0200
committerJasper Ras <jras@hostnet.nl>2025-04-15 19:44:48 +0200
commitc8c774ad7c0d98def2e83647d4f635ee275b66de (patch)
tree99e16d1cb376d00bcf449f140fb8845463feee7c /How to properly do options in a bash script with getopt!.md
parenteae6b57f17f5065a2bd3f130668043693f579cb4 (diff)
vault backup: 2025-04-15 19:44:48
Diffstat (limited to 'How to properly do options in a bash script with getopt!.md')
-rw-r--r--How to properly do options in a bash script with getopt!.md31
1 files changed, 31 insertions, 0 deletions
diff --git a/How to properly do options in a bash script with getopt!.md b/How to properly do options in a bash script with getopt!.md
new file mode 100644
index 0000000..7d417c5
--- /dev/null
+++ b/How to properly do options in a bash script with getopt!.md
@@ -0,0 +1,31 @@
+---
+tags:
+ - bash
+---
+```
+#!/bin/bash
+
+while getopts "ab:c" opt; do
+ case "$opt" in
+ a)
+ echo "Option -a was specified."
+ ;;
+ b)
+ echo "Option -b was specified with argument: $OPTARG"
+ ;;
+ c)
+ echo "Option -c was specified."
+ ;;
+ \?)
+ echo "Invalid option: -$OPTARG" >&2
+ exit 1
+ ;;
+ esac
+done
+
+shift $((OPTIND - 1))
+
+echo "Remaining arguments: $@"
+```
+
+man bash // getopt \ No newline at end of file