MPE/iX Shell and Utilities Reference Manual, Vol 1

getopt(1) MPE/iX Shell and Utilities getopt(1)
# Example illustrating use of getopt command. This
# shell script would implement the paste command,
# using getopt to process options, if the underlying
# functionality was embedded in hypothetical utilities
# hpaste and vpaste, which perform horizontal and
# vertical pasting respectively.
#
paste=vpaste # default is vertical pasting
seplist=" " # default separator is tab
set -- $(getopt -c $0 d:s "$@")
if [$?-ne0]
then print >&2 "Usage: $0 [-s] [-d seplist] file ..."
exit 1
fi
for o
do case "$o" in
-d) shift; seplist="$1"; shift;;
-s) paste=hpaste; shift;;
--) shift; break;;
esac
done
# perform actual paste command
$paste -d "$seplist" "$@"
DIAGNOSTICS
Possible exit status values are:
0 Successful completion.
1 An error occurred.
Messages
Message: Option –option argument missing
Cause: You specified option but did not provide the argument that optiondesc indi-
cated.
Action: Provide the missing argument.
Message: Missing -c cmd
Cause: You specified the –c option but did not provide a command name as its argu-
ment.
Action: Provide the missing argument.
1-254 Commands and Utilities