Skip to main content

If and else statements on Shell/Linux Terminal

If and Else


if and else are conditions statement that can be very useful and we are going to learn how to use them, lets first start our terminal and create a file in which we are going to create a simple security password program



We are about to create our script I have name it test and we are going to type the following



we are going to create a variable called VALID_PASSWORD with the value "secret", this means our password is secret (yes the actual password is secret), then we are going to read the value the user introduce with read PASSWORD

the if statement here will compare what the user introduce in PASSWORD with VALID_PASSWORD!, IF they are equal then it will print you have access if not then it will print ACCESS_DENIED!

is very important to close the IF statement with an 'FI' (FI closes the IF statement)

I hope this was useful and detailed enough to help you understand how does if and else works.

to try this all you need is 'bash' but is a default package so you don't need to download anything

Comments

Popular posts from this blog

Command Lines Part 2

Converting Files Images Convert from jpg to png? $ convert image.jpg image.png         Networking Stuff Arp Have a look at who on the network own which IP address: $ arp     Ping Is a server alive? $ ping 8.8.8.8     Traceroute Where are the network issues between us and them? $ traceroute www.nuim.ie     Nmap Scan the local 255 host subnet. $ nmap 192.168.1.0/24     1-Liners What is the total disk size of all MarkDown files in my homedir? $ find ~ -name "*.md" | xargs du -ch       Generate numbers in a random order echo {01..10} | sed 's/ /\n/g' | shuf -