From: John DuBois on 25 Apr 2010 12:38 In article <8d9d9210-c93c-44e2-9fc6-b7b6daee6c2e(a)z7g2000yqb.googlegroups.com>, Scott Bass <sas_l_739(a)yahoo.com.au> wrote: >Hi, > >I'm writing a script (ksh) where the user enters a date parameter as >follows: > >-a "begin time" > >Job will not start until after begin time >begin time is in the form of month:day:hour:minute where >month 1-12, day is 1-31, hour is 0-23 and minute is 0-59. >At least 2 fields must be given hour:minute, if 3 fields >are given they are assumed to be day:hour:minute. > >I would like to add error checking in the script, rather than having >the called utility choke on bad dates. > >I'd like to split the user parameter into fields, then check the >fields in my script. If you know there will be only one word in each field, as you might legitimately assume in this case, you can split into fields with e.g.: set -- ${foo//:/ /} which will replace the colons with space and thus be split on them. $1..$4 will be your fields. If you don't want to make that assumption: oIFS=$IFS IFS=: set -- $foo IFS=$oIFS There are some examples of date error-checking in this library, e.g. in unixdays(): ftp://ftp.armory.com/pub/lib/ksh/days John -- John DuBois spcecdt(a)armory.com KC6QKZ/AE http://www.armory.com/~spcecdt/ |