KEMBAR78
Linux Architecture | PDF | Shell (Computing) | System Software
100% found this document useful (1 vote)
34 views6 pages

Linux Architecture

pdf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
34 views6 pages

Linux Architecture

pdf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Linux Architecture

====================

1) Shell

2) Kernel

3) Hardware components : drivers, printers, disc....

Kernel is the core component is linux os. Kernel is responsible to communicate with Hardware
components.

Kernel will act as mediator between shell and linux hardware components.

Shell is a mediator between users and kernel. Our commands will be processed by shell only.

What is Scripting

=> Scripting means set of commands we are keeping in a file for execution.

=> Scripting is used to automate our daily routine work.

=> For example, i want to execute below commands on daily basis

Whoami

Pwd

date

cal

ls

Note: instead of executing these commands one after other manually we can keep them inside a file
and we can execute that file which is called as Scripting.

=> The process of executing script file using shell is called as Shell Scripting.

=> Shell scripting is used to automate our daily routine work in the project.

Note: Shell script files we will create using .sh extension.


================= 01 - Shell Script ===============

echo "Enter Your Name

read uname

echo "Hey $uname, welcome to cloud..."

==================02 - Shell Script ===============

#! /bin/bash

echo "Enter your firstname"

read fname

echo "Enter your lastname"

read lname

echo "Your Fullname : $fname $lname"

Variables

=> Variables are used to store the values

=> Variables will represent data in key-value format

a = 10

b = 20

Note: We don't have data types in shell scripting.

We have 2 types of variables

1) System Variables / Environment Variable

2) User Defined Variables

The variables which are already defined and using by our system are called as System variables.$
echo $SHELL

Note: We can access all the environmental variables using below command

$ env

The variables which we are creating for our requirement are called as 'User Defined Variables'.

name = sumit

id = 101
Note : To access value of variable we will use below syntax

$ echo $VARIABLE_NAME

# unset variable

# Access variables

$ echo $course

$ echo $trainer

Variables Rules

Variable names shouldn't start with digits

Variable names shouldn't contains special symbols Ex: - , @, #

Note: It is recommended to use UPPERCASE characters for variable names

Operators

Operators are used to perform some operation on variables.

Ex:a=10

b=20

a+b

Arithematic Operators ( + - * % / **)

Self Attempt : Rest of Operators

==================03 - Shell Script ===============

#! /bin/bash

echo "Enter first number"

read FNUM

echo "Enter second number"

read SNUM

result=`expr $FNUM + $SNUM`

echo "The sum is : $result


Conditional Statements

=> Conditional statements are used to execute commands based on condition.

Syntax :

if [ condition-1 ]; then

// stmt-1

else

// stmt-3

Fi

==================04 - Shell Script ==============

Requirement : Read user age and determine weather user is eligible for vote or not.

#! /bin/bash

echo "Enter Your Age"

read AGE

if [ $AGE -gt 18 ]; then

echo "Eligible For Vote"

else

echo "Not Eligible for vote"

fi

(Self Attempt ) Different types of if.

Looping Statements

=> Loops are used to execute statements multiple times.

For loop Syntax

for(( intialization ; condition ; modification ))

do

// statements
done

For loop example - Print Numbers from 1 to 10

===============================================

#! /bin/bash

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

do

echo "$i"

done

while loop

=> While loop is used to execute statements until condition is true

#! /bin/bash

N=1

while [ $N -le 10 ]

do

echo "$N"

(( N++))

done

Functions=> Functions are used to perform some action / task

Using functions we can divide big task into multiple small tasks.

=> Functions are used to divide our work logically

=> Functions are re-usable.syntax


# creating function

function funcName ( ) {

// function body

# call function

funcName

====================== Script with Function ===============

function welcome(){

echo "welcome to linux"

echo "welcome to devops"

Self Attempt (Function with arguments)

Self Attempt (Arrays )

You might also like