0

I am tasked with making a user menu that will have 2 different variations, one for the novice user and the others for an expert.

I got it calling all my novice scripts, but in order to call my expert scripts, my main script needs to detect if a user has passed any of the arguments like "help, man, status" etc. And if they do I need my main script to call expert scripts in that case.

I am very new to bash scripting so I hope I can get some guidance here.

#!/bin/bash
 echo -n "Name please? "
 read name
 echo "Menu for $name"
 echo "===================================================="
 echo -e "Enter 
 ( 1 ) File and Directory Managment Commands\nEnter
 ( 2 ) Text Processing Commands\nEnter
 ( 3 ) System Status Commands\nEnter
 ( 4 ) Exit"
  echo "Enter your choice :"
 read en
 case "$en" in
 1)sh ./fileNovice.sh;;
 2)sh ./textNovice.sh;;
 3)sh ./systemStatusNovice.sh;;
 4)echo "Good Bye..."
 sleep 0;;
 *)echo "Wrong Option selected" ;;
 esac
0

1 Answer 1

0

Do not reinvent the wheel and use Bash's select:

#!/usr/bin/env bash

declare -a level_names=([0]='Novice' [1]='Expert')
declare -i level=0

while :; do
  printf 'Current mode : %s\n' "${level_names[level]}"
  PS3='Enter your choice : '
  select _ in \
    'File and Directory Managment Commands' \
    'Text Processing Commands' \
    'System Status Commands' \
    "Switch to ${level_names[level ^ 1]} mode" \
    'Exit'; do
    case "$REPLY" in
      1) bash "./file${level_names[level]}.sh"; exit ;;
      2) bash "./text${level_names[level]}.sh"; exit ;;
      3) bash "./systemStatus${level_names[level]}.sh"; exit ;;
      4) level=$((level ^ 1)); break ;;
      5) exit ;;
      *) echo 'Wrong Option selected'; break ;;
    esac
  done
done
Sign up to request clarification or add additional context in comments.

4 Comments

so sorry to bother you with a stupid question like this but how exactly do I invoke the expert script in the terminal? I've tried so many combinations now. Basically, I guess I need to type the choice number followed by the help | man | other options. What would be the syntax for it?
@Milan as you asked any of the arguments like "help, man, status", then call your script with any of the arguments. Example: bash menuscript.sh help
I don't think i asked my question properly. Like when the user is presented with my script he gets the options from that first script. And if I press any of the available script works flawlessly. But I don't know how to access the Expert scripts. I have all the files ready. Like when I press 1 what else should I enter to invoke the Expert script milan@ubuntu:~$ ./MYHELP1.sh 1) File and Directory Managment Commands 2) Text Processing Commands 3) System Status Commands 4) Exit Enter your choice : 1 help Wrong Option selected Enter your choice :
@Milan changed the menu to switch between modes. Please next time write your question and requirement more explicitly or you will get lots of wasteful discussions and question closed.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.