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: Bruce Hohl
Subject: Re: [Help-bash] return to menu after stopping an interactive program
Date: Fri, 26 Apr 2019 11:35:38 -0400

My thinking was stuck in a loop and thus constrained by the parent/child
process mechanism ... the following method seems to do what I want:

ADDED TO ~/.bashrc
jh () {
echo 'Ctrl+Z to suspend a running job (if supported)
To raise suspended jobs 1-9, select 1-9 at menu
Else quit menu and use job control commands:
fg %ID to raise
kill %ID to stop'
}

# returns to menu when job is suspended
# returns to menu when raised job is stopped
mm () { clear; cat <<'END'
MENU
q     --> quit menu
l     --> ls -1
jh    --> job control help
top
lynx

ID    Status                  Name
END
jobs
echo

read -p "Enter choice " choice
echo
case $choice in
 (q)     ;; # exits
 (l)     { l;  echo; read -p 'Enter for menu'; mm; } ;;
 (jh)    { jh; echo; read -p 'Enter for menu'; mm; } ;;
 (lynx)  { lynx; mm; } ;;
 (top)   { top;  mm; } ;;
 ([1-9]) { fg %$choice; mm; } ;;
 (*)     { echo 'Invalid selection'; sleep 1; mm; }
esac
}

# Training wheels for a GUI lover :)

On Fri, Apr 26, 2019 at 9:00 AM Bruce Hohl <address@hidden> wrote:

> > Don't use exec here if you intend to do anything else.
> Disregard the exec.  That was just a test I was doing to achieve my
> desired end result.
> I did not mean to include that in my original posting.
>
> > First of all, no, they are not started as child processes, because you
> > used exec.  exec means that lynx REPLACES the script.
> Again, please disregard the exec (it was just a test).
> Without the exec I believe they are child processes.
>
> > Second, don't use Ctrl-Z to suspend a program that you're trying to exit
> from.
> I DO want to suspend, not exit.
>
> I am looking for away to automatically return to my "infinite loop menu"
> after suspending a process.
> Basically, I am trying to integrate bash job control features into a menu
> script.
>
>
> On Fri, Apr 26, 2019 at 8:30 AM Greg Wooledge <address@hidden> wrote:
>
>> 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]