Skip to content

Latest commit

 

History

History
52 lines (40 loc) · 946 Bytes

File metadata and controls

52 lines (40 loc) · 946 Bytes

Case Statments

  • Case statment is used for simplifying mulitple condition check with multiple different choices.

    echo "1. Shutdown"
    echo "2. Restart"
    echo "3. Exit Menu"
    read –p "Enter your choice: " choice
    
    case $choice in
    
        1) shutdown now
           ;;
        2) shutdown –r now
           ;;
        3) break
           ;;
        *) continue
           ;;
    
    esac
    

    cs

  • Case statement can also be written along with the while loop as shown

    while true
    do
      echo "1. Shutdown"
      echo "2. Restart"
      echo "3. Exit Menu"
      read –p "Enter your choice: " choice
    
      case $choice in
    
          1) shutdown now
             ;;
          2) shutdown –r now
             ;;
          3) break
             ;;
          *) continue
             ;;
    
      esac
    done
    

    cs1