The question is very simple. I was reading the man page of getopts but I see no description on how the opstring should be. So, how should I know? I know I can Google it but I want to know how to get the answer from the documentation.
Asked
Active
Viewed 118 times
0
-
Do you mean `getopt`? The C runtime library function for parsing command line parameters? – wallyk Jul 09 '14 at 04:38
-
I mean the command line parameter. – Gleiry Agustin Serrano Wong Jul 09 '14 at 04:39
-
Sure, but which interface to it? From a shell script? From a compiled program? From PHP? Etc. – wallyk Jul 09 '14 at 04:40
-
ohhh, sorry. I mean the wrapper for the shell script . – Gleiry Agustin Serrano Wong Jul 09 '14 at 04:44
1 Answers
2
When the documentation for a shell builtin function is murky, the best solution tends to be to find an understandable example. Grepping /bin/*
shows many uses (though since my system has a lot of developer packages, it might have more than normal).
/bin/smistrip
(at line 153) uses it like this:
while getopts Vhnm:i:d: c ; do
case $c in
n) test=1
;;
m) single=$OPTARG
;;
i) indir=$OPTARG
;;
d) dir=$OPTARG
;;
h) do_usage
exit 0
;;
V) do_version
exit 0
;;
*) do_usage
exit 1
;;
esac
done
This is very similar to how getopt() works from C. See man 3 getopt
for a clear example and explanation.

wallyk
- 56,922
- 16
- 83
- 148