Bash Shell Scripting For Beginners - Logical And & Logical Or
Mental Outlaw
In this video we discuss the logical AND and the logical OR operators in bash. you can get a more in depth explanation of these operators here https://en.wikipedia.org/wiki/Logical_conjunction Source code for the script used in this video ###Bash Logical Or and Logical And###
####Truth Tables###
True = True
False = False
True and True = True
True and False and True and True ... = False
False and True = False
False and False = False
True or True = True
True or False = True
False or True or False or False ... = True
False or False = False
true_var=true false_var=false #you don't have to compare a boolean variable to true, the below way is much better if $true_var = true; then echo 'This variable is true' else echo 'This variable is false' fi
if $true_var; then echo 'This variable is true' else echo 'This variable is false' fi
if $true_var; then echo 'This variable is true' else echo 'This variable is false' fi
###Logical And
if $true_var && $false_var ; then echo 'This variable is true' else echo 'This variable is false' fi
if $false_var && $false_var ; then echo 'This variable is true' else echo 'This variable is false' fi
###Logical Or
if $true_var || $false_var ; then echo 'This variable is true' else echo 'This variable is false' fi
if $true_var || $true_var ; then echo 'This variable is true' else echo 'This variable is false' fi
End First Script realistic example of using and or echo "enter you age" read age echo "are you a felon or are you innocent?" read criminal_status years=$(expr 18 - $age)
if [ $age -ge 18 ] && [ $criminal_status == "innocent" ]; then echo 'You may purchase a firearm' elif [ $age -le 18 ] && [ $criminal_status == "innocent" ]; then echo "You are too young kid, come back in ${years} years" elif [ $age -le 18 ] && [ $criminal_status == "felon" ]; then echo "You are on a bad road kid, stay in school" elif [ $age -ge 18 ] && [ $criminal_status == "felon" ]; then echo "You are a felon, we can't sell you a firearm!" fi End of second script
Subscribe to my YouTube channel http://goo.gl/9U10Wz and be sure to click that notification bell so you know when new videos are released. ₿💰💵💲Help Support the Channel by Donating Crypto💲💵💰₿
Bitcoin 3MMKHXPQrGHEsmdHaAGD59FWhKFGeUsAxV
Ethereum 0xeA4DA3F9BAb091Eb86921CA6E41712438f4E5079
Litecoin MBfrxLJMuw26hbVi2MjCVDFkkExz8rYvUF
Dash Xh9PXPEy5RoLJgFDGYCDjrbXdjshMaYerz
Zcash t1aWtU5SBpxuUWBSwDKy4gTkT2T1ZwtFvrr
Chainlink 0x0f7f21D267d2C9dbae17fd8c20012eFEA3678F14
Bitcoin Cash qz2st00dtu9e79zrq5wshsgaxsjw299n7c69th8ryp
Etherum Classic 0xeA641e59913960f578ad39A6B4d02051A5556BfC
USD Coin 0x0B ... https://www.youtube.com/watch?v=EYbJuvEfi7M
15196836 Bytes