- 5paisa
- AdSense
- Android
- Asphalt 8 : Airborne Mod Apk 4.9.1b Unlimited Money
- Battlegrounds Mobile India
- Blogger
- Blogging
- Bug Hunting
- cloud storage
- Cmd
- Damn vulnerable Web Application
- Demat Account
- Difference between
- dj alok
- dj alok in free firefree
- Doodle Army 2 : Mini Militia 5.2.0 Apk + Mod for android
- DVMA
- E-books
- earn Bitcoins
- Ethical hacking tutorials
- Express vpn
- EXPRESSVPN PRO APK 7.12.1
- EXPRESVPN CRACKED APK
- fire dj alok
- Freefire
- Gaming
- Google drive
- Google llc
- gplink
- Groww App
- Health
- helo
- helo mela
- helo app
- Helo app earn paytm
- Helo app full guide
- Helo app invite and earn
- Helo app redeem proof
- Helo app refer and earn
- Helo app unlimited trick
- Helo app withdraw proof
- Helo Mela Offer: Get Rs.2 Free Paytm Cash + Win Upto Rs.10000 Paytm Cash
- helo refer and earn
- How to
- How to combine two Wifi Connections to get a faster Internet
- how to get dj alok for free
- how to get free dj alok
- how to get free dj alok in free fire
- How to install DVWA on Kali Linux 2020.2
- How To Use Light Speed WebCache on Your website
- ICICI Direct
- IOS
- kali linux
- Live streaming
- makeup
- meesho
- Money Earning
- My poems
- Netflix
- Netflix mod
- Netflix premium
- News
- online courses
- Pentesting
- programming
- PUBG
- Puffin Browser Pro 8.3.0.41446 (Full) Apk + Mod for Android
- Puzzles
- Recharge offers
- Refer and Earn
- Reviews
- SEO
- shell Scripting
- Shortlink
- Spotify Music 8.5.57.1164 APK Mega Mod Cracked Latest Android
- stylish name
- Technology
- Tips&Tricks
- Township Mod Apk 7.5.0 Unlimited Money
- Udemy
- Udemy courses
- Udemy free
- Udemy premium
- VClip app download link
- VClip app full details
- VClip app invitation link
- VClip app referral code
- VClip app referral link
- VClip app review
- Web designing
- What is
- WINDOWS
- Wishes
- Wordpress
- World Cricket Championship 2 2.8.9 Apk + Mod (Coins/Unlocked)
- Youtube tricks
- zoom app
- zoom bombing
- zoom call
- Zoom safety tips
Conditional Statements if and else in Shell Scripting
Conditional statements if and else in scripting Linux
if statement
If the given Statement is true then it executes the result.else it shows as false.
its helps to control specific decisions.but the syntax is quite different with c language and c++
let's check out some examples.
Else Statement
if your statement is wrong then it doesn't execute internal code.if the given Statement is true then it executes the result.
By using above code let's check whether 143 is greater than 100 or not.Where above statement is correct prints true as result
Rules to create if statements
1)There must be spaces while starting square brackets and ending square bracket [ $num -gt 100 ] its a valid statement
2) if there is no spaces while starting square brackets and ending square bracket is a invalid statement [$num -gt 100]
3) you have to use then keyword along with if.when if condition is true then the positive result will be shown. Whatever you write after then keyword gets executed when given Statement is true.
4) fi keyword is commonly indicates the last line of the if condition.basically the code between then and fi gets executed when given statement is true.fi is ending tag for if statement.
-gt greater than.
-ge greater than and equal to.
-le less than and equal to.
-lt less than.
-ne not equal
Use operators with Scripts
-eq equal to
also try for other operators
paste below code in linux terminal hit enter
-f it tells shell to find file in your current directory
I hope you may loved this cool post.If you have any doubts post in comment section.
Please check out advertisements on our website which helps us to post more content for you .
Don't forget to share this cool post with all your friends and groupspread. HAVE A GREAT DAY.
if statement
If the given Statement is true then it executes the result.else it shows as false.
its helps to control specific decisions.but the syntax is quite different with c language and c++
let's check out some examples.
Else Statement
if your statement is wrong then it doesn't execute internal code.if the given Statement is true then it executes the result.
#!/bin/bashnum=143if [ $num -gt 100 ] thenecho "number $num is greater"else echo "number is smaller"fi
By using above code let's check whether 143 is greater than 100 or not.Where above statement is correct prints true as result
Rules to create if statements
1)There must be spaces while starting square brackets and ending square bracket [ $num -gt 100 ] its a valid statement
2) if there is no spaces while starting square brackets and ending square bracket is a invalid statement [$num -gt 100]
3) you have to use then keyword along with if.when if condition is true then the positive result will be shown. Whatever you write after then keyword gets executed when given Statement is true.
4) fi keyword is commonly indicates the last line of the if condition.basically the code between then and fi gets executed when given statement is true.fi is ending tag for if statement.
Operators of Shell Scripting
-eq equal to.-gt greater than.
-ge greater than and equal to.
-le less than and equal to.
-lt less than.
-ne not equal
Use operators with Scripts
-eq equal to
#!/bin/bashecho "enter first number"read num1echo "enter second number"read num2if [ $num1 -eq $num2 ] thenecho "numbers are equals"fi
-gt greater than
#!/bin/bash echo "enter first number"read num1echo "enter second number"read num2if [ $num1 -gt $num2 ] thenecho "$num1 is greater"elseecho "$num2 is greater"fi
-lt less than
#!/bin/bashecho "enter first number"read num1echo "enter second number"read num2if [ $num1 -lt $num2 ] thenecho "$num1 is lesseeer"elseecho "$num2 is lesser"fi
also try for other operators
check Whether File Exists or Not
Now let's check whether file is available in directory or notpaste below code in linux terminal hit enter
#!/bin/bashecho "enter a file name"read file if [ -f $file ] then echo "file exist"else echo "file does not exist"fi
-f it tells shell to find file in your current directory
let's search for directory or folder
copy below code and paste code in linux terminal hit enter#!/bin/bashecho "enter a file name"read file if [ -d $file ] then echo "file exist"else echo "file does not exist"fi
search files in specific directory
you have to give full path like exSdcard/Android/data/obb/com.tencent.ig shows pubg obb folder#!/bin/bashecho "enter a full path of file"read file if [ -f $file ] then echo "file exist"else echo "file does not exist"fi
conclusion
I hope you may loved this cool post.If you have any doubts post in comment section.
Please check out advertisements on our website which helps us to post more content for you .
Don't forget to share this cool post with all your friends and groupspread. HAVE A GREAT DAY.
Also Read
KUMAR JEERU
. I am a Programmer and Pentester. I find and Fix loophole in websites and networks. Connect with me for queries , web developemnt , Scanning and Fixing website Security issues. My company gives special discount for independent entrepreneur , small and Medium size companies. Contact me directly on my face page
Post a Comment
Post a Comment