0

I have a script that asks the user for input for options.

When selecting the option I have it so it runs a new terminal and executes another script for the specified option.

I still want the menu script on the first terminal to ask for user input rather than exiting the script. Some feedback on this would be greatly appreciated.

The following was copied from a comment by the OP:

Here is an example:

menue.sh

#!/binbash
clear
echo
echo
echo
echo "1. Option Here"
echo
echo -n "Choice"
read choice
echo $choice
case $choice in
  1) /root/scriptexample/./examplenewterminal.sh
     ;;
esac
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

examplenewterminal.sh

#!/bin/bash
xterm -e "/root/scriptexample/./example.sh"
bash
clear
echo

example.sh

#!bin/bash
clear
echo
echo
echo
echo
commands here, etc.
When you Control + C example.sh to stop commands executing, I want the xterm menu
to close and the script to continue to load the menue.sh in the original terminal.
| improve this question | | | | |
  • I'm not sure I completely understand. If you want to create a menu in a script, you're probably using something like `select opt in "${options[@]}", which you can then use in subsequent parts of the script in the same terminal - is that similar to what you're doing? Please post some of your code. – Tristan Reid Aug 12 '15 at 15:44
  • #!/binbash echo – Peaceful Aug 12 '15 at 17:13
  • here is an example menue.sh #!/binbash clear echo echo echo echo "1. Option Here" echo echo -n "Choice" read choice echo $choice case $choice in 1) /root/scriptexample/./examplenewterminal.sh;; esac ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ examplenewterminal.sh #!/bin/bash xterm -e "/root/scriptexample/./example.sh"; bash clear echo example.sh #!/bin/bash clear echo echo echo echo commands here etc when you control + c example.sh to stop commands executing I want the xterm menue to close and the script to continue to load the menue.sh in the original terminal. – Peaceful Aug 12 '15 at 17:24
  • Comments should be used, sparingly, for limited, succinct dialog with respondents.  When you are asked to post code or otherwise provide information to clarify your question — information that should have been in the question in the first place — your first instinct should be to edit the question and put the requested information there.  As you can see, posting code in a comment doesn’t work very well.  I have edited your question to try to include the code that you posted in a comment.  Please check it and edit it to fix it if there are problems. – Scott Aug 12 '15 at 18:52
1
  1. Your comment shows menue.sh starting with #!/binbash.  This should be #!/bin/bash.  Or, if you aren’t using any bash-specific code, you can just use #!/bin/sh.
  2. You seem to be calling your scripts (from within the other scripts) as /root/scriptexample/./examplenewterminal.sh and /root/scriptexample/./example.sh.  These should probably be just /root/scriptexample/examplenewterminal.sh and /root/scriptexample/example.sh; i.e., the /./ is unnecessary (and, while I guess it’s harmless, it’s confusing clutter).  You don’t need to use ./ whenever you’re running a script; you need to use it when you’re running a program (script or compiled binary) in the current directory.  See Problems when trying to execute sh file from another sh file.
  3. When example.sh terminates, examplenewterminal.sh should continue running.  It, apparently, starts another bash shell (which I don’t understand); after that terminates, examplenewterminal.sh clears the screen, echoes a blank line, and ends.  When examplenewterminal.sh terminates, menue.sh should continue running.  But then it ends.  (What is the ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ supposed to be?  Just a separator?)  If you add more code to menue.sh after the esac, or put the existing code into a loop, it should continue to run after examplenewterminal.sh terminates.
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.