>> I am writing a payroll script that accepts two command line parameters, two
>> times, starttime and endtime..
>> ie. $ payroll 09:30 14:25
>> The script starts with an error checking if statement designed to make sure
>> the user inputs the times in proper format, HH:MM
>> This is the line I have right now, but I keep getting an error message
>> if [ "$1" = [0-2][0-9][:][0-5][0-9] -a "$2" = [0-2][0-9][:][0-5][0-9] ]
>> Using a 24 hour clock that's why my range goes from 00:00 to 23:59
>> The error message I keep getting says
>> [: too many integers
>> Does anyone have any idea what I'm doing wrong? Or does anyone have a better
>> solution to do this format check?
>AFAIK, the [ command will not match with regexs. You'll need to
>either do something with grep, or use perl.
Right. [0-2][0-9][:][0-5][0-9] and [0-2][0-9][:][0-5][0-9] are probably
numerous test constructs as far as the shell (Bash, and POSIX I think) are
concerned. You didn't even say what kind of script, so I assume a sh. sh
does filename globbing itself, but not regexes of arbitrary strings. Like
Perl, Awk and the Plan9 shell `rc' have "compare regex against string",
but "compare regex to regex" sounds like something that might be provably
impossible or something anyway.
"[: too many integers" is probably failing at the first [ in "[0-2]".
The shell is very powerful, and thus confusing. You have to write it one
character at a time as pertains to the test command, in my experience.
I'd never imagine a big test construct like yours working on the first go.
You need to proceed in smaller steps. K.I.S.S.
Rick Hohensee
"So far, Linux doesn't have a lot of traction on the client
[Microsoft-ese for desktop computers], except in some university
environments."
Steve Ballmer of Microsoft, as quoted and remarked by John Schwartz
in the Washington Post, June 11 2000