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


Groups > gnu.bash.bug > #14625 > unrolled thread

Re: suspend and ||

Started byChet Ramey <chet.ramey@case.edu>
First post2018-09-21 11:54 -0400
Last post2018-09-21 11:54 -0400
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#14625 — Re: suspend and ||

FromChet Ramey <chet.ramey@case.edu>
Date2018-09-21 11:54 -0400
SubjectRe: suspend and ||
Message-ID<mailman.1098.1537545285.1284.bug-bash@gnu.org>
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/

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web