Two decision making statements are mentioned below ifelse statements caseesac

Two decision making statements are mentioned below

This preview shows page 10 - 14 out of 14 pages.

actions based on different conditions. Two decision making statements are mentioned below: if…else statements case…esac statements if..fi Statements The if construct is followed by a command. If an expression is to be tested, it is enclosed in square brackets. The then keyword is placed after the closing parenthesis. An if must end with a fi. Syntax:
Image of page 10
Lab Manual Operating System | CSL-320 if [ expression ] then Statements to be executed if true fi if..else...fi Statements The if…else…fi statements is the next form of control statements that allow shell to execute statements in more controlled way and making decision in two ways. Syntax if [ expression ] then Statement(s) to be executed if true else Statement(s) to be executed if true Task 3.1 Write a program that compares two numbers if ‘a’ is greater than ‘b’ it displays “a is greater than b”, otherwise it displays that ‘a is not equal to b’. Code OUTPUT
Image of page 11
Lab Manual Operating System | CSL-320 if…elif…elseif…fi Statement The if…elif…fi statement is to make correct decision out of several conditions. Syntax if [ expression 1 ] then Statement(s) to be executed if expression 1 is true elif [ expression 2] then Statement(s) to be executed if expression 2 is true elif [ expression 3] then Statement(s) to be executed if expression 3 is true else Statement(s) to be executed if no expression is true fi Task 3.2 Write a program that compares two numbers check whether the numbers are equal, a is greater than b or a is less than b. Code
Image of page 12
Lab Manual Operating System | CSL-320 OUTPUT case…easc Statement You can handle multiple if…elif statements to perform a multiway branch. However, this is not the best solution, especially when all the branches depend the value of single variable. Syntax case “word” in “pattern1”) Statement(s) to be executed if pattern1 matches;; “pattern2”) Statement(s) to be executed if pattern1 matches;; “pattern3”) Statement(s) to be executed if pattern1 matches;; easc Task 4 Write a program using “case” that inputs a fruit from the user and displays “Apple pie” on the input of apple, “I like banana” on the input of banana and “New Zealand famous for kiwi” on the input of kiwi.
Image of page 13
Lab Manual Operating System | CSL-320 OUTPUT
Image of page 14

You've reached the end of your free preview.

Want to read all 14 pages?

  • Fall '19
  • Steven Pearce
  • Test, Shell script, C shell

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes