We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a7f8843 commit 520011dCopy full SHA for 520011d
getopts.md
@@ -0,0 +1,26 @@
1
+An example of how to use ```getopts``` shell built-in command to process shell arguments.
2
+The use of ```getopts``` is actually well-known with old-timers.
3
+However, new gens are usually cycled to ```agrc``` and ```argv```.
4
+Save some time and use the built-in. :)
5
+
6
+```bash
7
+ while getopts df: flag
8
+ do
9
+ case $flag in
10
11
+ d)
12
+ echo debugging on
13
+ ;;
14
+ f)
15
+ file=$OPTARG
16
+ echo filename is $file
17
18
+ ?)
19
+ exit
20
21
+ esac
22
+ done
23
+shift $(( OPTIND - 1 )) # shift past the last flag or argument
24
25
+echo parameters are $*
26
+```
0 commit comments