SHELL SCRIPTING || PART 1

Shell scripting is writing a series of command for the shell to execute. 
If you don't know what is a shell it is nothing but  it provides you with an interface to the Unix system. It gathers input from you and executes programs based on that input.


HERE ALL COMMANDS ARE DISCUSSED MAKE SURE YOU SUBSCRIBE OUR BLOG AND FOLLOW THIS SERIES . SHARE AND SUPPORT.


ECHO

To print something in the shell the command used is echo 

example:  echo "hello"

result: hello

echo "HELLO"

note : spacing between echo and the string should be maintained.


PERSONALIZED ECHO

To make a personalized command using echo:


read name
echo "Welcome $name"


input: ADAM

RESULT: Welcome ADAM

LOOPING 

for number in {1..99..2}
do
    echo $number
done

 
If you want to print numbers within Particular range we can use loops in the Linux shell scripting 

If you give the command as shown as above

the result will be

1
3
5
.
.
.
.
. 
99 

LOOPING WITH  NUMBERS

If you want to display the natural numbers between 1 to 50.

for number in {1..50..1}
do
echo $number
done

  

{1..50..1}

here 1 is starting point 
and 50 is the end limit
and 1 is the number you chose to increment 

{1..50..1}
this syntax is similar to 

for(i=1;i<=50;i++)

This will result in 

1
2
3
4
5
.
.
.
.
.
50
  NOW LETS SEE HOW TO ADD,SUBTRACT,MULTIPLY,DIVIDE IN SHELL SCRIPTING.


read x
read y
echo $(( $x + $y ))
echo $(( $x - $y ))
echo $(( $x * $y ))
echo $(( $x / $y ))


First you should read two numbers (here x and y) and followed by commands
will display the output as

input:5,2

RESULT: 
7
3
10
2
Let's See more about SHELL SCRIPTING in next article. Follow us . 

PART TWO:CLICK HERE

Knowledge sharing is atmost quality of Knowledge gaining, Share the content to your friends.
For more content and quries SUBSCRIBE our blog.

Thankyou.











Post a Comment

0 Comments