Thanks for the note about two digit option. I did not know about that. I came
across another usenet message and it showed a different way of putting the
USAGE together. I like how this make the code look neater and more readable.
Time for more questions :)
* Is there a more detail/in-depth document discussing getopts and USAGE? There
is a bit in the man pages (man ksh) but nothing easily understandable.
* I expanded my DESCRIPTION to have paragraphs, but when I make the man page it
pushes it all together. Is there a way to have a bit more editorial control
over the content of this section? I tried to embed \n characters, but they are
ignored.
* for this test I set my flags to be 'aaa' or 'bbb', yet 'a' or 'aa' will be
acceptable. Is there a way to force to a specific value? or does this take
the first unique value (e.e 'aax' versus 'aaa'?)
* How did the suboptions (20 and 21) become negative?
Thanks
Eric
============ start of test.ksh ============
#! /bin/ksh
#>./test.ksh —help
#Usage: ./test.ksh [ options ]
#OPTIONS
# --date=<date value>
# Delivery date (YYYYMMDD or YYYYMMDDHH)
# --flag=<type> what type of flag are you setting?
# aaa desc of this type
# bbb and this does something else]
# --user Retrieve user data
# --media Retrieve media content
USAGE=$'
[-?
@(#)$Id: '$( basename $0 )' - test command line arguments $
]
[-author?Eric Peterson <email address>]
[-date?'$( date "+%a, %d %b %Y, %T %Z" )' -- now]
[+NAME?'$( basename $0 )' --- test command line arguments]
[+DESCRIPTION?Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Maecenas libero felis, interdum nec dictum a, pharetra pellentesque ipsum.
Vestibulum quis arcu et lectus venenatis posuere vel quis odio. Donec nunc
tortor, auctor sit amet ultrices id, volutpat nec tellus. Donec ornare auctor
consectetur.
Etiam porta nulla at eros tempor quis pharetra dui venenatis. Fusce adipiscing
malesuada nunc, in pulvinar lacus ultrices id. Duis quis mi nulla. Phasellus
accumsan metus lacinia erat sollicitudin sed aliquet quam tincidunt. Aenean
magna tortor, rutrum et adipiscing ac, tristique eu eros.
Nunc pharetra eleifend ultrices. Aenean condimentum sodales ligula, sit amet
sollicitudin erat aliquet in. In metus arcu, consectetur sed viverra vel,
volutpat ut nulla. In nec justo at nunc molestie luctus eu eu enim. Ut at elit
nulla, sed vulputate nulla. In ut blandit risus. Sed sit amet elementum est.
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per
inceptos himenaeos.
]
[10:date?Delivery date (YYYYMMDD or YYYYMMDDHH)]:[<date value>]
[11:flag?what type of flag are you setting?]:[<type>]{
[20:aaa?desc of this type]
[21:bbb?and this does something else]
}
[12:user?Retrieve user data]
[13:media?Retrieve media content]
'
if (( $# == 0 ))
then
$0 --help
exit 1
fi
dt_date=
fl_flag=
integer fl_user=0
integer fl_media=0
while getopts "${USAGE}" optchar
do
case ${optchar} in
10) dt_date=${OPTARG} ;;
11)
case $(( abs( ${OPTARG} ) )) in
20) fl_flag='aaa' ;;
21) fl_flag='bbb' ;;
esac ;;
12) fl_user=1 ;;
13) fl_media=1 ;;
*) $0 --help >/dev/stderr; exit 1 ;;
esac
done
if [[ -z ${dt_date} ]]
then
print -u2 '***> ERR: Missing date value'
$0 --help >/dev/stderr
exit 1
fi
if (( fl_user == 0 )) && (( fl_media == 0 ))
then
print -u2 '***> ERR: one or both retrieval flags must be on command line'
$0 --help >/dev/stderr
exit 1
fi
print "dt_date : [${dt_date}]"
print "fl_flag : [${fl_flag}]"
print "fl_user : [${fl_user}]"
print "fl_media : [${fl_media}]"
============ end of test.ksh ============
<SNIP>
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users