Path: utzoo!utgpu!water!watmath!clyde!att-cb!att-ih!pacbell!ames!necntc!dandelion!ulowell!apollo!nazgul From: nazgul@apollo.uucp (Kee Hinckley) Newsgroups: comp.sys.apollo Subject: Re: shell scripts, boolean variables, and eon Message-ID: <3b313c29.b0a1@apollo.uucp> Date: 1 Apr 88 02:04:00 GMT References: <8803241941.AA09455@ELI.CS.YALE.EDU> Reply-To: nazgul@morgul.UUCP (Kee Hinckley) Organization: Apollo Computer, Chelmsford, MA Lines: 56 In article <8803241941.AA09455@ELI.CS.YALE.EDU> hanks-steven@YALE.ARPA (Steven Hanks) writes: > executing the following shell script produces weird > results: > > #!/com/sh > > eon > > truevar := true > falsevar := false > > if ^truevar then args "yes" else args "no" endif > if not ^truevar then args "yes" else args "no" endif > if ^falsevar then args "yes" else args "no" endif > if not ^falsevar then args "yes" else args "no" endif > That's a common shell problem (one of these days I should post a summary of common problems). There are two "not"s. One negates commands, the other negates expressions. Boolean values only make sense inside of expressions. The case above would in fact work fine if you happened to have executable files called "true" and "false" in your search path, since in the context of a command the variables are converted to strings, but anyway... What you want to say is: if (( ^truevar )) then args "yes" else args "no" endif if (( not ^truevar )) then args "yes" else args "no" endif if (( ^falsevar )) then args "yes" else args "no" endif if (( not ^falsevar )) then args "yes" else args "no" endif I'm sorry about the (( )) syntax (which is necessary for all expressions except the special case of assignments (e.g. (( a := 1 )) isn't necessary)). We needed some way to differentiate between expressions and commands (the shell didn't have variables or any expression capability until SR8) without breaking any old scripts and "(( ))" looked pretty safe, albeit awkward. BTW, the necessity to use "eon" to turn on variable evaluation (unless you feel like putting all your variables in double parenthesis) came about as a last minute addition for much the same reason. It turned out that people were constructing Pascal code in shell here-documents catf <