Get the App
SLTechnology News&Howtos  ›  Servers  › 

Methods of using logical or & and in shell scripts

Shulou Source: shulou.com Published: 2022-06-02 04:35:34 10月04日 Update

This article mainly introduces the use of logic or & and in the shell script, the article is very detailed, has a certain reference value, interested friends must read it!

Logical or & and operations are very useful when using multiple conditions in our program (script). Or between two or more conditions. If any condition returns true, it returns true. And used between two or more conditions. True is returned only if all conditions are returned to true.

Use logical or

Logic may be used with the operator-o in bash scripts. The following shell script shows how to use logical OR (- o) between two conditions.

#! / bin/bashread-p "Enter First Numeric Value:" firstread-p "Enter Second Numeric Value:" secondif [$first-le 10-o$second-gt 20] then echo "OK" else echo "Not OK" fi

Use logic vs.

The logic in the bash script is used with the operator-a. The following shell script shows how to use logic and (- a) between two conditions.

#! / bin/bashread-p "Enter First Numeric Value:" firstread-p "Enter Second Numeric Value:" secondif [$first-le 10-a$second-gt 20] then echo "OK" else echo "Not OK" fi

Logic or & mixed with

The following example shows how to use multiple logical operators in a single statement.

#! / bin/bashread-p "Enter Your Number:" iif [($I-ge 10-a $I-le 20)-o ($I-ge 100-a $I-le 200)] then echo "OK" else echo "Not OK" fi is all the content that uses logical or & and methods in shell scripts. Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Logic script condition two between multiple operator face operation method content value interest single only boy partner is in more useful Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi vpn OPPO Reno Microsoft Shulou Information