this command (source below)
test-getopts --date=now --flag=aaa --flag=bbb --user --media --verbose
prints
:10=now:11=-20:11=-21:12=1:13=1:14=1:
for ksh93 versions as old as 2001-05-04
modulo suboption bugs for these releases:
2007-11-15 :10=now:11=aaa:11=bbb:12=:13=:14=:
2007-11-20 :10=now:11=aaa:11=bbb:12=:13=:14=:
2007-11-27 :10=now:11=aaa:11=bbb:12=:13=:14=:
for releases since 2008-08-08 this
ksh -c 'print $((KSH_VERSION))'
will print the ksh release version as YYYYMMDD so it can be used in arithmetic
and lexicographic comparisons
cat > test-getopts <<'!'
USAGE=$'
[-]
[10:date?Set the delivery date to \adate\a.]:[date]
[11:flag?Set the foobar to \atype\a.]:[type]
{
[20:aaa?Desc of this type.]
[21:bbb?And this does something else.]
}
[12:user?Retrieve user data.]
[13:media?Retrieve media content.]
[14:verbose?Verbosity is good sometimes.]
'
while getopts "${USAGE}" OPT
do print -n -- ":$OPT=$OPTARG"
done
print ":"
!
On Tue, 9 Feb 2010 14:27:32 -0800 Eric Peterson wrote:
> of the machines I have available to me (print ${.sh.version}):
> 93e is just too old
> Version M-12/28/93e
> ./test.ksh: line 64: .sh.file: parameter not set
> My mac:
> Version M 1993-12-28 s+
> GNU/Linux
> Version M 93s+ 2008-01-31
> Version JM 93t+ 2009-05-01
> Seems the sub-options are returned differently from the version of ksh93s
> on my Mac to the ksh93s on the linux box. So below I have to check for which
> version I am working on. I would have expected the OPTARG for the sub-option
> to be 20 or 21, from the USAGE description. Did I define the USAGE
> incorrectly? or am I looking for the suboptions (20 & 21) incorrectly?
> Is there a way to get the version as a numerical value? So that it can be
> compared to a minimum version that works for this app. For example the sh.
> compound variable showed up at some point (93m?).
> I see sometimes the date is the third value in the version string,
> sometimes the fourth, sometimes part of the second (at least in the boxes
> I've looked at). Is there a regex to parse the various version string
> formats?
> Thanks
> Eric
> USAGE=$'
> ...
> [10:date?Delivery date (YYYYMMDD or YYYMMDDHH)]:[<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]
> [14:verbose?Verbosity is good sometimes]
> ...
> '
> ...
> while getopts "${USAGE}" optchar
> do
> case ${optchar} in
> 10) dt_date=${OPTARG} ;;
> 11)
> if [[ ${.sh.version} == "Version M 1993-12-28 s+" ]]
> then
> # ---------- ---------- ----------
> # this version returns OPTARG as a negative
> # value of what is defined in USAGE
> # ---------- ---------- ----------
> case $(( abs( ${OPTARG} ) )) in
> 20) fl_flag='aaa' ;;
> 21) fl_flag='bbb' ;;
> esac
> else
> # ---------- ---------- ----------
> # otherwise it doesn't return OPTARG as
> # a defined number in USAGE but the value itself
> # ---------- ---------- ----------
> fl_flag=${OPTARG}
> fi
> ...
> _______________________________________________
> ast-users mailing list
> [email protected]
> https://mailman.research.att.com/mailman/listinfo/ast-users
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users