The inconsistency between the command flags of various Unix systems is a perpetual problem and causes lots of grief for users who switch between any of the major releases, particularly between a commercial Unix (Solaris, HP-UX, and so on) and an open source Linux system. One command that demonstrates this problem is quota , which supports full-word flags on some Unix systems, while on others it accepts only one-letter flags.
A succinct shell script solves the problem, however, by mapping any full-word flags specified into the equivalent single-letter alternatives:
#!/bin/sh # newquota - A front end to quota that works with full-word flags a la GNU. # quota has three possible flags, -g, -v, and -q, but this script # allows them to be '--group', '--verbose', and '--quiet' too: flags="" realquota="/usr/bin/quota" while [ $# -gt 0 ] do case in --help ) echo "Usage:#!/bin/sh # newquota - A front end to quota that works with full-word flags a la GNU. # quota has three possible flags, -g, -v, and -q, but this script # allows them to be '--group', '--verbose', and '--quiet' too: flags="" realquota="/usr/bin/quota" while [ $# -gt 0 ] do case $1 in --help ) echo "Usage: $0 [--group --verbose --quiet -gvq]" >&2 exit 1 ;; --group - group ) flags="$flags -g"; shift ;; --verbose -verbose) flags="$flags -v"; shift ;; --quiet -quiet) flags="$flags -q"; shift ;; -- ) shift; break ;; * ) break; # done with 'while' loop! esac done exec $realquota $flags "$@"[--group --verbose --quiet -gvq]" >&2 exit 1 ;; --group -group) flags="$flags -g"; shift ;; --verbose -verbose) flags="$flags -v"; shift ;; --quiet -quiet) flags="$flags -q"; shift ;; -- ) shift; break ;; * ) break; # done with 'while' loop! esac done exec $realquota $flags "$@"
Did you notice that this script accepts both single- and double-dash prefixes for full words, making it actually a bit more flexible than the standard open source version, which insists on a single dash for one-letter flags and a double dash for full-word flags? With wrappers, the sky's the limit in terms of improved usability and increased consistency across commands.
There are a couple of ways to integrate a wrapper of this nature into your system. The most obvious is to rename the base quota command, rename this script quota , and then change the value of the realquota variable set at the beginning of the script. But you can also ensure that users have a PATH that looks in local directories before it looks in the standard Unix binary distro directories (e.g., /usr/local/bin before /bin and /usr/bin ), which relies on the safe assumption that each user 's PATH will see the script before it sees the real command. A third way is to add systemwide aliases so that a user typing quota actually invokes the newquota script.
$ newquota --verbose Disk quotas for user dtint (uid 24810): Filesystem usage quota limit grace files quota limit grace /usr 338262 614400 675840 10703 120000 126000 $ newquota -quiet
The -q (quiet) mode emits output only if the user is over quota. You can see that this is working correctly from the last result because I'm not over quota.