[Novalug] nohup and chaining commands

Bud Roth junk@taiotoshi.org
Thu Oct 23 15:15:45 EDT 2008


As a follow-up question, I'm curious.  Why the below:

# nohup sh -c "cmd1 --output=/path/to/file; chmod 666 /path/to/file" &

versus

# nohup sh -c "cmd1 --output=/path/to/file && chmod 666 /path/to/file" &

I thought that "&&" was better than ";" because it allows the second
command to execute only upon successful execution of the first.
(Successful execution producing an exit state of "1", which is true and
allows the shell to interpret the second part of the logical AND.)  

";", on the other hand, allows the second command to execute regardless
of the outcome of the first.

The reasons for preferring "&&" are twofold: (1) You avoid executing a
second command that may not make sense or possibly do harm and (2) You
find out where the linked commands failed because the shell stops at the
failure point instead of continuing on (possibly hiding the fact that an
early command failed).

Is that logic not applicable here?  If not, I'm curious why?

Regards,

Bud

On Thu, 2008-10-23 at 12:49 -0400, Jon Taimanglo wrote:
> The recommendation for:
> 
> nohup sh -c "cmd1 --output=/path/to/file; chmod 666 /path/to/file" &
> 
> worked.  So all is well.
> 
> Thanks to all those who replied and to the helpful thought of rtfm.
> 
> On Thu, Oct 23, 2008 at 11:55 AM, Peter Larsen
> <plarsen@famlarsen.homelinux.com> wrote:
>         On Thu, 2008-10-23 at 08:21 -0400, Jon Taimanglo wrote:
>         
>         > I want to chain together multiple commands.  The first
>         command usually
>         > takes a while to run and I usually background it:
>         >
>         > nohup cmd1 &
>         
>         
>         Lots of other people have already commented on this. I wanted
>         to try to
>         point you towards "screen". I think in your case, it will
>         serve you a
>         lot better. There's a simplistic "screen" called "detached"
>         but I think
>         screen is simple enough to learn in 5-10 minutes.
>         
>         --
>         Peter Larsen <plarsen@famlarsen.homelinux.com>
> 
> _______________________________________________
> Novalug mailing list
> Novalug@calypso.tux.org
> http://calypso.tux.org/cgi-bin/mailman/listinfo/novalug
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <https://lists.firemountain.net/pipermail/novalug/attachments/20081023/a2ea3905/attachment.asc>


More information about the Novalug mailing list