#!/bin/bash

# Check for file parameter
if [ -z "$1" ] || [ ! -f "$1" ]; then
  echo "Please provide a valid file as parameter."
  exit 1
fi

file=$1

# Loop for menu
while true; do
  echo "1. Sort by Name"
  echo "2. Delete an employee"
  echo "3. Add an employee"
  echo "4. Exit"
  read -p "Choose an option: " option

  case $option in
    1) sort -t ':' -k2 "$file" | more ;;
    2) read -p "Enter the ID to delete: " id
       grep -v "^$id:" "$file" > temp && mv temp "$file" ;;
    3) read -p "Enter ID: " id
       read -p "Enter Name and Surname: " name
       read -p "Enter Salary: " salary
       echo "$id:$name:$salary" >> "$file" ;;
    4) exit 0 ;;
    *) echo "Invalid option" ;;
  esac
done
