TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [TCLUG:2032] confused with bash script



In a message dated 98-10-31 12:29:01 EST, you write:

<<   if [ $datafile = $QUERY ] ; t >>
if $datafile is blank then when the shell expands the above it will have 
if [ = xxx ]; 
where xxx is the value in QUERY.

The "[" is like an alias for the "test" command. So it sees in its input just
"= xxx"
and not "something = xxx" and gets confused since the = is an operator but
then it is at the beginning of the expression that "[" has to evaluate. 

so it churns out :
[: =: unary operator expected 

Since you can only have unary operators like "!" or "-" in the beginning of an
expression.

You can change that by replacing your iffs with something like:
if [ "a$datafile" = "a$QUERY" ]

that way even if datafile or QUERY are null/blank strings the expression will
evaluate
to at leaset "a" = "a".