Home > Operation and Maintenance > Linux Operation and Maintenance > How to use logical OR & and in shell script

How to use logical OR & and in shell script

不言
Release: 2019-03-19 16:10:39
Original
5277 people have browsed it

Logical OR & AND operations are very useful when using multiple conditions in our programs (scripts). Or used between two or more conditions. If any of the conditions returns true, then true is returned. Used between two or more conditions. True will be returned only if all conditions return true.

How to use logical OR & and in shell script

Use logical OR

Logical OR is used with operator -o in a bash script. The following shell script will show how to use logical OR (-o) between two conditions.

#!/bin/bash
read -p "Enter First Numeric Value: "   first
read -p "Enter Second Numeric Value: "  second
if [ $first -le 10-o$second -gt 20 ]
then
        echo "OK"
else
	echo "Not OK"
fi
Copy after login

Use logical with

Logical AND and operator-a in bash script. The following shell script will show how to use logical AND (-a) between two conditions.

#!/bin/bash

read -p "Enter First Numeric Value: "   first
read -p "Enter Second Numeric Value: "  second


if [ $first -le 10-a$second -gt 20 ]
then
        echo "OK"
else
	echo "Not OK"
fi
Copy after login

Logical OR & mixed with

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

#!/bin/bash
read -p "Enter Your Number:"  i
if [ ( $i -ge 10  -a  $i -le 20 ) -o ( $i -ge 100  -a  $i -le 200 ) ]
then
        echo "OK"
else
	echo "Not OK"
fi
Copy after login

This article has ended here. For more other exciting content, you can pay attention to the Linux Tutorial Video column of the PHP Chinese website!

The above is the detailed content of How to use logical OR & and in shell script. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template