Question

(c) Write a shell program to illustrate the case statement.

15 Apr 2024
Answer :
Word Count : 274

A `case` statement in a shell script is used to execute one of the several possible branches based on the value of a variable. Below is an example of a shell script using the `case` statement in Linux to illustrate how it works. This script prompts the user to input a number and then prints a corresponding message based on that input.

```bash
#!/bin/bash

# Prompt user for input
echo "Enter a number between 1 and 3: "
read num

# Case statement to match user input
___ _______ ___ __________ __________ ______ ______ ________ _____.
_______ ________ _________ ____ ____ __________ __________ ________.
_______ ______ ____ ________ _________ _______ ____.
_____ ___ ______ ___ __________ _______ ________ ________ _______.
___ ________ ____ _______ __________ _______ ____ _______ _________ _____.
___ __________ _____ ____ ___ ______.
___ __________ ________ ________ ___.
___ ______ __________ _____ ____ ____ ________ ____ __________ ____.
_________ ____ ___ ______ _________ _____ ___ _________ _________ __________ ____.
__________ ________ __________ _____ ____ _____ ___ ________ ____ __________ _________ _______.
_______ ____ __________ ____ ________ __________ ____ _______ _____ ___ _______.
________ ______ ____ _____ ________ ______ ____ _________ _______ _________ ________.
___ ____ ______ ________ __________ ______ _______ ____ __________ ________.
_____ ______ ____ ______ ____ ________.
_______ ______ __________ _____ ______ ______ ______ ____ ____ _____.
____ _______ __________ ________ _______ _______ ________.
________ __________ _______ ___ ______ ___ ______ _______ ___ _____ _______.
____ __________ _____ ________ _______ _____ ___.
_____ ___ _______ _______ ______ ______ _______ ________ ___.
_______ ________ ____ ________ __________ ____.
__________ ______ __________ ________ __________ ____ ___ _________ _____.

IGNOU ACADEMY
Your IGNOU journey, made easier.
  • Solved Assignments
  • Study Notes
  • Guess Papers
  • Question Papers
Skip in 10
'; fetch( "query.php?type=1&method=0&lr=0&app=401&mycartproduct=1", { method: "GET", cache: "no-store" } ) .then(function(response) { if (!response.ok) { throw new Error( "HTTP " + response.status ); } return response.text(); }) .then(function(html) { loader.innerHTML = html; /* Your existing function, if available. */ if (typeof updateTotals === "function") { updateTotals(); } else { calculateCartTotal(); } }) .catch(function(error) { console.error( "Cart loading error:", error ); loader.innerHTML = '
Unable to load cart.
'; });}/* ========================================================= CALCULATE TOTAL========================================================= */function calculateCartTotal() { let subtotal = 0; /* Looks for .item-price inside AJAX products. Examples accepted: ₹200 ₹200.00 Rs 200 Rs. 200 200 200.00 */ const prices = document.querySelectorAll( '#loadmycart .item-price' ); prices.forEach(function(element) { let text = element.textContent || ''; text = text .replace(/₹/g, '') .replace(/Rs\.?/gi, '') .replace(/,/g, '') .trim(); let value = parseFloat(text); if (!isNaN(value)) { subtotal += value; } }); updateCartDisplay(subtotal);}/* ========================================================= UPDATE TOTAL DISPLAY========================================================= */function updateCartDisplay(total) { const subtotalElement = document.getElementById('subtotal'); const totalElement = document.getElementById('total'); const checkoutButton = document.getElementById('checkoutButton'); const noItems = document.getElementById('noitems'); const amount = Number(total) || 0; if (subtotalElement) { subtotalElement.textContent = '₹' + amount.toFixed(2); } if (totalElement) { totalElement.textContent = '₹' + amount.toFixed(2); } /* EMPTY CART */ if (amount
Top