Published on March 13, 2017 by ProgrammingKnowledge
Want create site? Find Free WordPress Themes and plugins.

The Logical AND “&&” is a boolean operator that executes following commands based on the outcome of previously executed commands.
Logical AND (&&) if [[expr1 && expr2]] Returns expr1 if it can be converted to false; otherwise, returns expr2. Thus, when used with Boolean values, && returns true if both operands are true; otherwise, returns false.

– for using And operator use &&
if [ “$age” -gt 18] && [“$age” -lt 30 ]

– The -a option provide an alternative compound condition test.
if [ “$age” -gt 18 -a “$age” -lt 30 ]

– if [[ $condition1 && $condition2 ]] # Also works.
if [[ “$age” -gt 18 && “$age” -lt 30 ]]

Did you find apk for android? You can find new Free Android Games and apps.

Leave a Reply

4 Comments on "Shell Scripting Tutorial for Beginners 8 – Logical ‘AND’ Operator"

Notify of
avatar

Kaushal Agarwal
Guest
Kaushal Agarwal
3 months 7 days ago

hello sir, in echo commands as well as some other places, sometimes u use inverted commas("") and sometimes don't. Can u plz tell when to use them

Paras Shaw
Guest
Paras Shaw
3 months 22 days ago

Y doesn't it work when i take the age as keyboard input

Youngjin Kang
Guest
Youngjin Kang
7 months 10 days ago

Do we really need quotation marks around "$age"?

jurchiks101
Guest
jurchiks101
8 months 8 days ago

Maaan, Unix and their multiple choices for everything…

wpDiscuz