[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: bash: problem with [sets]



Colin Watson wrote:

On Mon, Jun 23, 2003 at 07:57:07PM +0100, David selby wrote:
My bash masterpeice is almost complete ... I have one last problem that no matter how many "" or '' I use I cannot get around.

I need to use an if...then construct to check that my 4 digit date field is 4 numerical digits.This is for error checking. I thought [sets] was the way to go ....

if [ $fourdig = [0-9][0-9][0-9][0-9] ]; then ......

Nope - read the expr(1) manual page to find out how to do pattern
matching. And yes, you do need quotes (single quotes, unless you know
you need to interpolate something within double quotes) around that to
stop the shell accidentally expanding it to any files with four-digit
filenames in the current directory.

It has occured to me that perhaps [sets] are not allowed as a
conditional test.

They aren't. [ ... = ... ] tests *equality*, not pattern matching.

Cheers,

Yes, fundermental misunderstanding on my part, this grep ^[0-9]*$ is an ingenious solution, Im still trying to get my head around .....

Many thanks
Dave



Reply to: