(66 lines)
1 .\" Manpage for arg.2 .\" Contact bruce@bruce-hill.com to correct errors or typos.3 .TH man 8 "14 February 2019" "1.0" "arg man page"4 .SH NAME5 arg \- A minimalist command line argument parser6 .SH SYNOPSIS7 .B arg8 .I flag9 .I ...10 .SH DESCRIPTION11 This is a handy tool for parsing out a single argument from a list of command12 line arguments.14 .SH INPUT15 The first argument must be a flag (for example \fB-f\fR, \fB--foo\fR, or16 \fBfoo\fR). This flag will be searched for among the remaining arguments.18 .SH OUTPUT AND RETURN19 If the flag is found, the program will exit successfully (exit status 0),20 otherwise the program will fail (exit status 1). A flag is found if:22 .RS 423 .HP 224 \fB-\fR one of the extra arguments is an exact match:25 \fBarg --foo .. \fI--foo\fB [<value>]\fR27 .HP 228 \fB-\fR one of the exact arguments begins with the flag followed by an '=' sign:29 \fBarg --foo .. \fI--foo=\fB[<value>]\fR31 .HP 232 \fB-\fR or the flag is a single dash followed by a single letter, and the letter33 is found clustered with other letters after a single dash:34 \fBarg -f .. -x\fIf\fBy\fR36 If a value is found, the value is printed to stdout.38 .RE40 .SH EXAMPLES41 The primary use case of this program is for shell scripting, as a much simpler42 and easier to use alternative to getopt. Here are some simple shell script43 examples:45 .TP46 .B47 if foo=`arg --foo "$@"`; then echo "foo is '$foo'"; fi48 If \fI--foo=value\fR or \fI--foo value\fR are in the arguments, the shell script49 will print "foo is 'value'".51 Note: it is important to put quotes around \fB$@\fR to ensure that52 arguments with spaces get passed correctly.54 .TP55 .B56 if arg -v "$@" || arg --verbose "$@"; then echo "Verbose!"; fi57 Prints "Verbose!" if the shell script was run with either \fI-v\fR or \fI--verbose\fR.59 .TP60 .B61 prefix=`arg prefix "$@" || echo "/usr/local"`62 Sets prefix to the value of the \fIprefix\fR flag the user pased in, or if63 no such flag was passed, \fI/usr/local\fR.65 .SH AUTHOR66 Bruce Hill (bruce@bruce-hill.com)