I have a script with a main menu done using a case statement. The script runs, welcome screen info is echo'ed to the screen, user hits enter to clear welcome screen stuff (empty read statement), user is asked to input a number corresponding to the menu item (read menuNum). It works fine as is, but I want to expand functionality a bit and allow the user to skip the welcome screen and go straight to a menu item by using an argument when running the script.
For example if my menu is: 1) file operations 2) user info 3) processes, then i want the user to type "scriptfile.sh file" into the console to go straight to the file menu. This would somehow assign menuNum=1.
I don't know if this is possible using redirection of input, or really if it's possible at all. Any help or hints would be greatly appreciated. Thank you.
Basically, this is my script:
#!/bin/bash
#DEFINE ARGUMENTS
if [[ "$1" = "man" ]]; then man ./manpage.txt; exit; fi #argument "man" opens man page, closes main script
if [ "$1" = "debug" ]
then clear
echo -e "This area provides debug information:\n"
echo -e "There's a lot here, but it's not related to my question."
echo -e "\nPress [Enter] to continue."
read
fi
if [[ "$1" = "file" ]]; then bash tsharonfp.sh < 1; exit; fi #go straight to file menu
if [[ "$1" = "user" ]]; then bash tsharonfp.sh < 2; exit; fi #go straight to user menu
if [[ "$1" = "info" ]]; then bash tsharonfp.sh < 3; exit; fi #go straight to info menu
if [[ "$1" = "fun" ]]; then bash tsharonfp.sh < 4; exit; fi #go straight to fun menu
if [[ "$1" = "process" ]]; then bash tsharonfp.sh < 5; exit; fi #go straight to proc menu
#/DEFINE ARGUMENTS
clear
echo -e "My script title, contact info, and other stuff gets printed to screen here."
read #hitting enter clears welcome screen stuff
clear
while : #opens while1 loop
do #while1 loop
echo -e "Main Menu\n"
echo -e "[1] File Menu\n[2] User Menu\n[3] Info Menu\n[4] Fun Menu\n[5] Process Menu\n[88] Exit\n[99] Shutdown"
echo -ne "\nEnter Choice: "
read menuNum
case $menuNum in #open mainmenu case
1) #File;; #statement isn't commented, of course, but you get the idea
2) #user;;
3) #info;;
4) #fun;;
5) #proc;;
88) exit;;
99) shutdown -h;;
*) echo "invalid input";;
esac #closes mainmenu case
done #closes while1 loop
if [[ "$1" = "file" ]]; then bash tsharonfp.sh 1; exit; finot withtsharonfp.sh <1;[[, only inside[(even if the values have embedded spaces). You only need to quote literals when they have embedded whitespace. 2. You might considerthen exec bash tsharonfp.sh "$1" fi. Usingexecmeans there is no need toexit(unlessexecfails). 3. probably best to modularise your script.