0
  #!/bin/bash
  echo "Please, select your choice (1-4):"
  echo 1- Add Course
  echo 2- Delete Course
  echo 3- Search Course
  echo 4- exit
  read input

  case $input in
    1)
            script1
            ;;
    2)
            script2
            ;;
    3)
            script3
            ;;
    4)
            exit 0
            ;;
    *)
            echo Invalid choice
  esac

1 is associated with the file Add.sh

2 is associated with the file delete.sh

3 is associated with the file seatch.sh

4 is to exit

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Iam
  • 13
  • 4

1 Answers1

0

Using the builtin select command means you don't need to reinvent menus.

#!/usr/bin/env bash

# assuming all the scripts reside in the same directory as this one
script_path="$(dirname "$0")"

PS3="Please, select your choice: "
select choice in "Add Course" "Delete Course" "Search Course" "exit"; do
    case $input in
        "Add Course")    bash "$script_path/add.sh" ;;
        "Delete Course") bash "$script_path/delete.sh" ;;
        "Search Course") bash "$script_path/search.sh" ;;
        exit)            break ;;
    esac
done

I could get fancier to avoid the duplicated strings, but that's unneeded complexity.

Depending on the contents of those scripts, you might want to source them instead of running them in a different process. It might be simple to even put them in functions in the current script instead of having to maintain several separate files.

glenn jackman
  • 238,783
  • 38
  • 220
  • 352