A terminal argument parsing tool.
Go to file
2019-02-14 19:40:34 -08:00
arg.c initial commit 2019-02-14 19:17:02 -08:00
LICENSE initial commit 2019-02-14 19:17:02 -08:00
Makefile initial commit 2019-02-14 19:17:02 -08:00
README.md Added readme 2019-02-14 19:40:34 -08:00

arg - A simple command line argument parser

This is a simple tool with a simple job: figure out the value of a single command line argument. Tools like getopt and getopts are much too complicated. It's much nicer to be able to write shell scripts like this:

#!/bin/sh
dir=`arg --dir "$@" || arg -d "$@" || echo "$HOME/Downloads"`
if arg -v "$@" || arg --verbose "$@"; then
    echo "Downloading to $dir"
fi
cd $path && curl -O example.com/file.zip

Usage

arg -f ..., arg -flag ..., or arg --flag .... If arg finds the given flag among the rest of the command line arguments, it will print the flag's value (if any) and exit successfully, otherwise, it will fail (exit status 1). The value may be of the form --flag=value, --flag value, -f value. Single-letter flags will match when grouped with other single letter flags, but will not have a value, i.e. arg -b -abc foo will exit successfully without printing anything. When using arg in a shell script, it is best to use quotes around $@, as in arg --foo "$@", so arguments with spaces will parse properly, like my_script.sh --flag "one two".