Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the shell Boolean operators and logical operators

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "what are the shell Boolean operators and logical operators". In the operation of practical cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Boolean operator

The following lists the commonly used Boolean operators, assuming that the variable an is 10 and the variable b is 20:

Operator illustration example! If the expression is true, it returns false, otherwise it returns true. [! False] returns true. -o or operation. If an expression is true, true is returned. [B-gt 100] returns true. -an and operation, both expressions are true before returning true. [B-gt 100] returns false.

Examples of instance Boolean operators are as follows:

#! / bin/bash# author: rookie tutorial # url:www.runoob.coma=10b=20if [$a! = $b] thenecho "$a! = $b: an is not equal to b" elseecho "$a = = $b: an equals b" fiif [$a-lt 100a $b-gt 15] thenecho "$a less than 100and $b greater than 15: return true" elseecho "$a less than 100and $b greater than 15: return false" fiif [$a-lt 100o $b-gt 100] thenecho "$a less than 100or $b big Return true "elseecho" $a less than 100 or $b greater than 100: return false "fiif [$a-lt 5-o $b-gt 100] thenecho" $a less than 5 or $b greater than 100: return true "elseecho" $a less than 5 or $b greater than 100: return false "fi

Execute the script, and the output is as follows:

10! = 20: a does not mean that b10 is less than 100and 20 is greater than 15: return true10 less than 100or 20 greater than 100. return true10 less than 5 or 20 greater than 100. return false logical operator

The following describes the logical operator of Shell, assuming that the variable an is 10 and the variable b is 20:

Operator description example & logical AND [[a-lt 100 & & b-gt 100]] returns false | | logical OR [[b-gt 100]] returns true

An example of the instance logical operator is as follows:

Example #! / bin/bash# author: rookie tutorial # url:www.runoob.coma=10b=20if [[$a-lt & & $b-gt]] thenecho "return true" elseecho "return false" fiif [[$a-lt 100 | | $b-gt 100]] thenecho "return true" elseecho "return false" fi

Execute the script, and the output is as follows:

Return false and return true "what are the shell Boolean operators and logical operators"? that's it. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 302

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report