Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

logical operator precedence

Status
Not open for further replies.

huangwason

Programmer
Oct 10, 2006
21
DE
To check a file, if it does not exit, assign a value to exit code and print out something, I use the following code:

[ -f $FILE ] || EXIT_CODE=1 && echo "$FILE does not exist"

assure $FILE does not exist, the above logical operator can be regarded as:
(False || TRUE) && TRUE

EXIT_CODE is assigned to 1, it is ok.
but for &&, as long as the return exit code of || is 0, it print out, the result is it always print out, which is not my intension.

is there a solution to make the above logical operation doing like this
False || (TRUE && TRUE)

thanks
 
curly brackets

[tt][ -f $FILE ] || { EXIT_CODE=1 && echo "$FILE does not exist"; }[/tt]

but this is the same:

[tt][ -f $FILE ] || { EXIT_CODE=1; echo "$FILE does not exist"; }[/tt]



HTH,

p5wizard
 
I'd use this:
Code:
[ ! -f $FILE ] && EXIT_CODE=1 && echo "$FILE does not exist"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top