0% found this document useful (0 votes)
69 views

Operating Systems: Lab 03 Shell Scripts Lab Instructor: Zainab Iftikhar

This document provides information about mathematical operators, string comparisons, file and directory tests, logical operators, and examples of arithmetic operations, conversion between uppercase and lowercase, if/if-else/if-elif conditions, for and while loops, and functions in shell scripts. Mathematical operators like -eq, -ne, -lt, -le, -gt, and -ge are used for numeric comparisons, while string operators test string equality and existence. File and directory tests check types and permissions. Logical operators include !, -a, and -o. Examples demonstrate basic programming constructs like conditionals, loops, and defining reusable functions.

Uploaded by

SyEda SamReen
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views

Operating Systems: Lab 03 Shell Scripts Lab Instructor: Zainab Iftikhar

This document provides information about mathematical operators, string comparisons, file and directory tests, logical operators, and examples of arithmetic operations, conversion between uppercase and lowercase, if/if-else/if-elif conditions, for and while loops, and functions in shell scripts. Mathematical operators like -eq, -ne, -lt, -le, -gt, and -ge are used for numeric comparisons, while string operators test string equality and existence. File and directory tests check types and permissions. Logical operators include !, -a, and -o. Examples demonstrate basic programming constructs like conditionals, loops, and defining reusable functions.

Uploaded by

SyEda SamReen
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Operating Systems

Lab 03
Shell Scripts
Lab Instructor: Zainab Iftikhar
Mathematical Operators

Mathematical Meaning Normal But in Shell


Operator in Arithmetical/
Shell Script Mathematical
Statements

For test statement For [ expr ] statement


with if command with if command

-eq is equal to 5 == 6 if test 5 -eq 6 if [ 5 -eq 6 ]


-ne is not equal to 5 != 6 if test 5 -ne 6 if [ 5 -ne 6 ]
-lt is less than 5<6 if test 5 -lt 6 if [ 5 -lt 6 ]
-le is less than or 5 <= 6 if test 5 -le 6 if [ 5 -le 6 ]
equal to
-gt is greater than 5>6 if test 5 -gt 6 if [ 5 -gt 6 ]
-ge is greater than or 5 >= 6 if test 5 -ge 6 if [ 5 -ge 6 ]
equal to
String Comparisons

Operator Meaning
string1 = string2 string1 is equal to string2

string1 != string2 string1 is NOT equal to string2

string1 string1 is NOT NULL or not defined

-n string1 string1 is NOT NULL and does exist

-z string1 string1 is NULL and does exist


Test for File and Directory Types

Test Meaning
-s file Non empty file
-f file Is File exist or normal file and not a directory
-d dir Is Directory exist and not a file
-w file Is writeable file
-r file Is read-only file
-x file Is file is executable

Logical Operators
Operator Meaning
! expression Logical NOT
expression1 -a expression2 Logical AND
expression1 -o expression2 Logical OR
Using Arithmetic Operations
Code:

Output:
Example Uppercase to Lowercase
Conversion & Vice Versa
Code:

Output:
If Condition Example

Code:

Output:
If-else Condition Example
Code:

Output:
If-elif Condition Example
Code:

Output:
If-elif Condition Example

Code:

Output:
Case Statement Example
Code:

Output:
for Loop Example
Code:

Output:
for Loop Example

Code:

Output:
while Loop Example

Code:

Output:
Functions

 Sequence of statements that can be called anywhere


in script

Used for
Good organization
Create re-usable sequences of commands
Function Example
Code:

Output:
Function Example
Code:

Output:
Function Example
Code:
Output
Thank You!

You might also like