Note that there are some explanatory texts on larger screens.

plurals
  1. PObash, shell script argument to skip part of script
    primarykey
    data
    text
    <p>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. </p> <p>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. </p> <p>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.</p> <p>Basically, this is my script:</p> <pre><code>#!/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 &lt; 1; exit; fi #go straight to file menu if [[ "$1" = "user" ]]; then bash tsharonfp.sh &lt; 2; exit; fi #go straight to user menu if [[ "$1" = "info" ]]; then bash tsharonfp.sh &lt; 3; exit; fi #go straight to info menu if [[ "$1" = "fun" ]]; then bash tsharonfp.sh &lt; 4; exit; fi #go straight to fun menu if [[ "$1" = "process" ]]; then bash tsharonfp.sh &lt; 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 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload