0% found this document useful (0 votes)
25 views11 pages

Lab 2

This document provides information about shell scripts including: - Shell scripts allow automation of tasks through a series of commands written in plain text. They have more power than batch files in MS-DOS. - Reasons for writing shell scripts include taking user input/output, creating custom commands, automation, and system administration tasks. - Shell scripts can be written in any text editor and made executable by setting permissions through graphical or command line interfaces. - The document demonstrates simple shell scripts and discusses variables in shell scripts including system, user defined, and parametric variables.

Uploaded by

SyEda SamReen
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
0% found this document useful (0 votes)
25 views11 pages

Lab 2

This document provides information about shell scripts including: - Shell scripts allow automation of tasks through a series of commands written in plain text. They have more power than batch files in MS-DOS. - Reasons for writing shell scripts include taking user input/output, creating custom commands, automation, and system administration tasks. - Shell scripts can be written in any text editor and made executable by setting permissions through graphical or command line interfaces. - The document demonstrates simple shell scripts and discusses variables in shell scripts including system, user defined, and parametric variables.

Uploaded by

SyEda SamReen
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/ 11

Operating Systems

Lab 02
Shell Scripts
Lab Instructor: Zainab Iftikhar
Shell Scripting
Shell Scripting

Shell Script is series of command written in plain


text file. Shell script is just like batch file is MS-DOS but
have more power than the MS-DOS batch file."
 Why to write shell scripts?
o Shell script can take input from user, file and output them
on screen.
o Useful to create our own commands.
o Save lots of time.
o To automate some task of day today life.
o System Administration part can be also automated.
How to write shell scripts

 Use any editor to write shell script


 Set the execute permission for your script through
o Graphical interface
o chmod +x script-name
o chmod 755 script-name
My First Shell Script
Code:
Save the file as s1.sh in Home

Output:
My Second Shell Script
Code:

Save the file as s1.sh in Home


Commands to run on terminal

Output:
Variables in Shell

 In Linux shell there are three types of variables


System variables
User defined variables
Parametric variables
User Defined Variables

 Rules for defining variables


o Name must start with an alphanumeric character
o Can use underscore in between the characters
o Don't put spaces on either side of the equal sign
when assigning value to variable
 var=10
o NULLvariable declaration
 var=
 var=“”
 Do not use ?,* to name your variable names
User Defined Variables

 Defining user variables


o no=10
o Variable „no‟ is assigned value 10

 Accessing/printing variables
o Toaccess variables use „$‟
o echo $no
User Defined Variables Example
Code:

Output:

You might also like