bug-bash
[Top][All Lists]
Advanced

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

Re: suspend and ||


From: Chet Ramey
Subject: Re: suspend and ||
Date: Fri, 21 Sep 2018 11:54:33 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.9.1

On 9/21/18 7:49 AM, address@hidden 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:
> 
> address@hidden:~$ sleep 10 || echo hey
> ^Z
> [5]+  Stopped                 sleep 10
> hey
> address@hidden:~$ 
> 
> 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    address@hidden    http://tiswww.cwru.edu/~chet/



reply via email to

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