Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14625

Re: suspend and ||

From Chet Ramey <chet.ramey@case.edu>
Newsgroups gnu.bash.bug
Subject Re: suspend and ||
Date 2018-09-21 11:54 -0400
Message-ID <mailman.1098.1537545285.1284.bug-bash@gnu.org> (permalink)
References <201809211149.w8LBnLo2018762@omac.gsyc.urjc.es>

Show all headers | View raw


On 9/21/18 7:49 AM, esoriano@gsyc.urjc.es wrote:
> According to the manual:
> 
> (I)  Typing the suspend character (typically ^Z, Control-Z) 
>      while a process is running causes that process to be
>      stopped and returns control to bash.
> 
> (II) An OR list has the form
> 
>               command1 || command2
> 
>      command2  is executed if and only if command1
>      returns a non-zero exit status.  The return status of
>      AND and OR lists is the exit status of the last 
>      command executed in the list.
> 
> In the following example:
> 
> esoriano@omac:~$ sleep 10 || echo hey
> ^Z
> [5]+  Stopped                 sleep 10
> hey
> esoriano@omac:~$ 
> 
> there are two different issues:
> 
> (I) echo is executed when sleep is suspended, i.e., command2 is 
>    executed before command1 exits.

This is true, and it's the difference between a process, which is the
object you suspend, and a shell command. When you suspend the sleep,
it returns a status: 128+SIGTSTP. Since this is non-zero, the second
part of the AND-OR list gets executed.

The idiomatic way to do what you want is to get the command you want
to run as a unit into a construct like (...) -- if you want to run it
in the foreground -- so you have a single process that you can suspend.

This has come up many times, in the context of compound commands like
loops and command sequences.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: suspend and || Chet Ramey <chet.ramey@case.edu> - 2018-09-21 11:54 -0400

csiph-web