Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: "Parse Error: Condition Expected"

On Nov 3, 12:41pm, DPD wrote:
} Subject: "Parse Error: Condition Expected"
}         if [ $user = "" ]               ************************** LINE #48
}             if [ $user = "root" ]      *************************LINE #54

Change those to

        if [ "$user" = "" ]
            if [ "$user" = "root" ]

and your parse errors will go away.

} After some searchin', I used the "od -a 'filename'" command to look at
} the output  each time the loop went through.  I found that the last 
} read was storing an 'nl' in the variable "user" - which I hypothesized 
} to mean 'new line' (correct me if I'm wrong).
} (BTW, the first line of the od output is: 0000000  nl)

There's no "nl" stored in $user -- there's an empty string stored in it.
The "nl" is an artifact of how you ran "od" as far as I can tell.

} Apparently and rightfully so, this issue is causing the 'parse 
} error...' in both of the "if" statements within this loop...right??

What's causing the parse error is that $user is empty, so zsh sees

	if [ = "" ]

You have to put quotes around the variable reference to turn an empty
variable into an empty string for parsing purposes.

Bart Schaefer                             Brass Lantern Enterprises
http://www.well.com/user/barts            http://www.nbn.com/people/lantern

Messages sorted by: Reverse Date, Date, Thread, Author