- 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
Input and Variables in Shell Scripting
Input and variables in Shell ScriptingCommands
In this tutorial we are going to discuss
of shell scripting . Where taking input is easy way in shell scripting. Now let's make our own user friendly script
Keyboard or user input in Shell Scripting
if we need to take input we must use read command.
Copy below code and paste in terminal also don't forget to make this code executable
Where in line 1 shows shebang.it's a correct bash intepreter
In 2nd line shows the function of the code as a comment.
This line does not gives any result
Where in 4th line is a inbuilt command in linux.it asks users to enter some input from your keyboard.
by help of read commmand we have to instruct a variable that to store the input received from keyboard.
If you need to print some variable on output screen you have to add $ symbol before the variable.
The programming structure to other languages like javascript,linux,rubyc, c++,java and python in shell scripting.
lets checkout some examples.
Where shell declares it as a general statement.
For this we have to change that code into commandexpr.
But how i am going to explain now
you have to put expr before every mathematical expression then the code starts working.here You can use two ways to perform arithmetic operations in bash scripting . Through Expr function and some inbuilt functions in bash scripting like double parenthesis to perform arithmetic operations
How to use expr Function in Bash Scripting
copy the below code and paste it in Linux terminal and execute then code works fine
#!/bin/bash
#Arithmetic operations in bash
num1=134
num2=33
add=`expr $num1 + $num2`
rem=`expr $num1 % $num2 `
div=`expr $num1 / $num2`
multiplication=`expr $num1 \* $num2`
echo "addition is : $add"
echo "Remainder is: $rem"
echo "Multiplication is: $multiplication"
echo "Division is $div"
2)expressions must as `starts and ends with reversequote` can be commonly used for mathematical expression.
3)We have to put some space between variable and operator.
36+56 or num1+num2 is error expression.
35 + 56 or num1 + num2 is a valid expression.
4) Where * symbol can't be used for multiplication purposes in Linux because it us
is wild card operator .so we have to discard wild card operator by \.
1)You shouldn't use echo function
2)it can print expression value to general output from.
3)Get output quickly without typing vast code.Just type as i shows here get output result instantly
expr 9 + 8
expr 9 - 8
expr 9 \* 8
expr 9 % 8
if you want to do multiple calculations in shell scripting you must place your variables or values in between double parenthesis .it's the ultimate easy way to maths in bash.
copy the below code and paste in your Linux terminal tap enter to run
i have explained everything in previous articles.
Let's make Calculator in Linux
we might already developed calculator with html,java script,css.
Now we are going to make a working calucalator with bash script.
copy the below code and paste in your Linux terminal tap enter to run
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 groups. HAVE A GREAT DAY.
In this tutorial we are going to discuss
User Input Arithmetic Operator
Still we have learned basics ofof shell scripting . Where taking input is easy way in shell scripting. Now let's make our own user friendly script
Keyboard or user input in Shell Scripting
if we need to take input we must use read command.
Copy below code and paste in terminal also don't forget to make this code executable
#!/bin/bash
#Keyboard input in shell scripting
echo "Enter your name"
read name
echo "Hello boss MR $name"
Where in line 1 shows shebang.it's a correct bash intepreter
In 2nd line shows the function of the code as a comment.
This line does not gives any result
Where in 4th line is a inbuilt command in linux.it asks users to enter some input from your keyboard.
by help of read commmand we have to instruct a variable that to store the input received from keyboard.
If you need to print some variable on output screen you have to add $ symbol before the variable.
Arithmetic operations with Shell Scripting
We might have used Arithmetic operations in different programming language.The programming structure to other languages like javascript,linux,rubyc, c++,java and python in shell scripting.
lets checkout some examples.
num1=92num2=184Now we have to add both numbers.
echo $num1+$num2This is invalid statement gives a error in result on output screen.
Where shell declares it as a general statement.
For this we have to change that code into commandexpr.
But how i am going to explain now
you have to put expr before every mathematical expression then the code starts working.here You can use two ways to perform arithmetic operations in bash scripting . Through Expr function and some inbuilt functions in bash scripting like double parenthesis to perform arithmetic operations
How to use expr Function in Bash Scripting
copy the below code and paste it in Linux terminal and execute then code works fine
#!/bin/bash
#Arithmetic operations in bash
num1=134
num2=33
add=`expr $num1 + $num2`
rem=`expr $num1 % $num2 `
div=`expr $num1 / $num2`
multiplication=`expr $num1 \* $num2`
echo "addition is : $add"
echo "Remainder is: $rem"
echo "Multiplication is: $multiplication"
echo "Division is $div"
some important rules of expr function
expr: Is an inbuilt function it tells bash to evaluate expressions as the mathematical expressions.2)expressions must as `starts and ends with reversequote` can be commonly used for mathematical expression.
3)We have to put some space between variable and operator.
36+56 or num1+num2 is error expression.
35 + 56 or num1 + num2 is a valid expression.
4) Where * symbol can't be used for multiplication purposes in Linux because it us
is wild card operator .so we have to discard wild card operator by \.
More examples on expr
1)You shouldn't use echo function
2)it can print expression value to general output from.
3)Get output quickly without typing vast code.Just type as i shows here get output result instantly
expr 9 + 8
expr 9 - 8
expr 9 \* 8
expr 9 % 8
Use double parenthesis in bash script
if you want to do multiple calculations in shell scripting you must place your variables or values in between double parenthesis .it's the ultimate easy way to maths in bash.copy the below code and paste in your Linux terminal tap enter to run
#!/bin/bash
#Arithmetic operations in bash with double parenthesis format
num1=143
num2=363
div=$((num1 / num2))
add=$((num1 + num2))
multi=$((num1 * num2))
remainder=$((num1 % num2))
echo "addition is $add"
echo "division is $div"
echo "multiplication is $multi"
echo "remainder is $remainder"
i have explained everything in previous articles.
Let's make Calculator in Linux
we might already developed calculator with html,java script,css.
Now we are going to make a working calucalator with bash script.
copy the below code and paste in your Linux terminal tap enter to run
#!/bin/bash
#Arithmetic operations in bash with double parenthesis formatecho "Enter first integer"read num1echo "enter second integer"read num2add=$((num1+num2))multi=$((num1*num2))div=$((num1/num2))remain=$((num1%num2))echo "addition is $add"echo "Division is $div"echo "remainder is $remain"echo "multiplication is $multi"
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 groups. 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