help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] return to menu after stopping an interactive program


From: Greg Wooledge
Subject: Re: [Help-bash] return to menu after stopping an interactive program
Date: Fri, 26 Apr 2019 08:30:34 -0400
User-agent: Mutt/1.10.1 (2018-07-13)

On Fri, Apr 26, 2019 at 08:21:11AM -0400, Bruce Hohl wrote:
> read -p "Enter choice " choice
> echo
> case $choice in
>  (ls)   ls; echo; read -p 'enter for menu';;
>  (lynx) exec lynx;;
>  (top)  exec top;;
>  (q|Q)  break
>  (*)
> esac
> done
> exit 0

Don't use exec here if you intend to do anything else.

> The programs are started as child processes of the 'menu'
> script.  If lynx is selected/started, then Ctrl-Z is used
> to stop lynx, it is reported that 'menu' has been stopped:
> [1]+  Stopped                 menu

First of all, no, they are not started as child processes, because you
used exec.  exec means that lynx REPLACES the script.  There is no more
script.  It's gone.

Second, don't use Ctrl-Z to suspend a program that you're trying to
exit from.  Simply exit from the program normally.

In the case of lynx, you exit by pressing q and then y to confirm.  In
the general case, do whatever the normal way of exiting is for whatever
program you're in.

> What I really want is to stop the selected item (lynx)
> and be returned to the (running) menu. Is there a way
> to do this with interactive programs?

You may want to look at <https://mywiki.wooledge.org/BashFAQ/115>.

Basically, what you want to do is run an infinite loop which prints
the menu, reads the user's choice, takes some action, and then continues
the loop, forever.  You get back to the menu loop by exiting from
whatever program the menu launches.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]