Loading…
OS · Decisions · Program 18 · In the record
Write the shell script using infinite loop to multiply and subtract the two number using case statement
1#!/bin/bash2 3while true4do5 echo6 echo "1. Multiply"7 echo "2. Subtract"8 echo "3. Exit"9 echo "Enter your choice:"10 read choice11 12 case $choice in13 1)14 echo "Enter two numbers:"15 read a b16 echo "$a x $b = $((a * b))"17 ;;18 2)19 echo "Enter two numbers:"20 read a b21 echo "$a - $b = $((a - b))"22 ;;23 3)24 echo "Exiting..."25 exit 026 ;;27 *)28 echo "Invalid choice"29 ;;30 esac31done1 ⏎ 6 7 ⏎ 2 ⏎ 20 8 ⏎ 31. Multiply 2. Subtract 3. Exit Enter your choice: 1 Enter two numbers: 6 7 6 x 7 = 42 1. Multiply 2. Subtract 3. Exit Enter your choice: 2 Enter two numbers: 20 8 20 - 8 = 12 1. Multiply 2. Subtract 3. Exit Enter your choice: 3 Exiting...
Run program 18 in your browser
bash · just-bash. Change the code or the input, run it, break it, and see what happens.