• Tidak ada hasil yang ditemukan

Daffodil International University

N/A
N/A
Protected

Academic year: 2024

Membagikan "Daffodil International University"

Copied!
4
0
0

Teks penuh

(1)

Daffodil International University

Department of Computer Science and Engineering

Lab Manual

Version: 2017.04

Course Code: CSE 324

Course Title: Operating System Lab

(2)

Department of Computer Science and Engineering

CSE324: Operating System Lab Credits: 3 Lab Manual v.1.0

Copyright © Daffodil International University, 2017 3

Session 7: Decision making in shell scripting (3 Hrs.)

Intended Learning Outcome:

a. Write shell script with decision making

Expected skills:

Solve shell script problems involved with decision making

Tools Required:

Ubuntu

Session Detail:

In this season we would discuss about if-else & switch case conditions in shell scripts.

If-else:

The if...else...fi statement is the next form of control statement that allows Shell to execute statements in a controlled way and make the right choice.

Comparisons:

-eq equal to

-ne not equal to -lt less than

-le less than or equal to -gt greater than

-ge greater than or equal to

File Operations:

-s file exists and is not empty -f file exists and is not a directory -d directory exists

-x file is executable -w file is writable -r file is readable

(3)

Department of Computer Science and Engineering

CSE324: Operating System Lab Credits: 3 Lab Manual v.1.0

Copyright © Daffodil International University, 2017 4

Syntax:

if [ expression]

then

Statement(s) to be executed if expression is true else

Statement(s) to be executed if expression is not true fi

Example:

#!/bin/sh

a=10 b=20

if [ $a == $b ] then

echo "a is equal to b"

else

echo "a is not equal to b"

fi

Else-if:

Syntax:

if [ expression]

then

Statement(s) to be executed if expression is true elif [ expression ]

then

Statement(s) to be executed if expression is true else

Statement(s) to be executed if expression is not true fi

Example:

#!/bin/bash

if [ "$1" = "cool”]

then

echo "Cool Beans"

elif [ "$1" = "neat”]

then

(4)

Department of Computer Science and Engineering

CSE324: Operating System Lab Credits: 3 Lab Manual v.1.0

Copyright © Daffodil International University, 2017 5

echo "Neato cool"

else

echo "Not Cool Beans"

fi

switch case:

it’s like if else with a little difference. In hare we can choose our option and can get required answer.

Syntax:

case $variable in pattern-1) commands ;;

pattern-2) commands ;;

pattern-3) commands ;;

pattern-N) commands ;;

*)

commands ;;

esac

Lab exercise:

1. Make a GPA result displayer 2. Find greater number 3. find Number is Even or Odd

4. Find the number is positive or negative

5. Find out your age conditions. If you are less than 20 or greater than 50, you are out of the age range. If you are between 20 and 30 you are in your 20's and so on.

Post Lab Exercise:

a. Solve exercise on decision making problems

Further Readings:

Shell scripting related problems available online.

Referensi

Dokumen terkait

1 of 2 Daffodil International University School of Science and Engineering Department of Civil Engineering Term Final Examination, Fall-2019 Course Title: Transport Engineering I

Daffodil International University Department of Electrical and Electronic Engineering Faculty of Engineering Final Examination of Summer – 2021 Course Code – EEE 315 Course

Business Process Modeling Abdus Sattar Assistant Professor Department of Computer Science and Engineering Daffodil International University Email: [email protected]... 2

Daffodil International University Department of Computer Science and Engineering Faculty of Science and Information Technology Mid Term Examination, Semester: Summer-2020 Course

Daffodil International University Department of Computer Science and Engineering Faculty of Science & Information Technology Final Examination, Fall 2020 @ DIU Blended Learning

APPROVAL This Project titled Design and development of security equipment market Secured BD, submitted by Al-Amin to the Department of Computer Science and Engineering, Daffodil

Touhid Bhuiyan Chairman Professor and Head Department of Computer Science and Engineering Faculty of Science & Information Technology Daffodil International University Zahid Hasan

S M Aminul Haque Associate Professor and Associate Head Department of Computer Science Engineering Daffodil International University Co-Supervised By Ms.. Tania Khatun