cmd1 | gzip -f ... && cmd2 : Command concatenation with condition: Execute cmd2 only if cmd1 (or gzip) fails/succeeds? - Networking

This is a discussion on cmd1 | gzip -f ... && cmd2 : Command concatenation with condition: Execute cmd2 only if cmd1 (or gzip) fails/succeeds? - Networking ; I am not sure about on how to specify that a second command should only be execute in case that the first command fails/succeeds. When I enter: cmd1 | gzip -f ... && cmd2 Is then cmd2 executed only if ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: cmd1 | gzip -f ... && cmd2 : Command concatenation with condition: Execute cmd2 only if cmd1 (or gzip) fails/succeeds?

  1. cmd1 | gzip -f ... && cmd2 : Command concatenation with condition: Execute cmd2 only if cmd1 (or gzip) fails/succeeds?

    I am not sure about on how to specify that a second command should only be execute in case
    that the first command fails/succeeds.

    When I enter:

    cmd1 | gzip -f ... && cmd2

    Is then cmd2 executed only if cmd1 is finished successfully or if gzip is finished successfully?

    Is the command concatenation "&&" correct at all?

    What if I want cmd2 only to execute if both (cmd1 and gzip) end successfully?

    What about the other way: cmd2 should only be executed if

    a) cmd1 failed

    b) cmd1 or gzip failed?

    Matthew

  2. Re: cmd1 | gzip -f ... && cmd2 : Command concatenation with

    On Tue, 17 Jun 2008 06:16:24 +0000, Matthew Lincoln rearranged some
    electrons to say:

    > I am not sure about on how to specify that a second command should only
    > be execute in case that the first command fails/succeeds.
    >
    > When I enter:
    >
    > cmd1 | gzip -f ... && cmd2
    >
    > Is then cmd2 executed only if cmd1 is finished successfully or if gzip
    > is finished successfully?
    >
    > Is the command concatenation "&&" correct at all?
    >
    > What if I want cmd2 only to execute if both (cmd1 and gzip) end
    > successfully?
    >
    > What about the other way: cmd2 should only be executed if
    >
    > a) cmd1 failed
    >
    > b) cmd1 or gzip failed?
    >
    > Matthew


    Didn't you read the responses the first time you posted this question 3
    days ago?

    Seems like you would be better off writing a small script to do what you
    want.

    man bash


  3. Re: cmd1 | gzip -f ... && cmd2 : Command concatenation with condition: Execute cmd2 only if cmd1 (or gzip) fails/succeeds?

    Greetings.

    In article <485756b8$0$6616$9b4e6d93@newsspool2.arcor-online.net>, Matthew
    Lincoln wrote:
    > I am not sure about on how to specify that a second command should only
    > be execute in case that the first command fails/succeeds.
    >
    > When I enter:
    >
    > cmd1 | gzip -f ... && cmd2
    >
    > Is then cmd2 executed only if cmd1 is finished successfully or if gzip is
    > finished successfully?
    >
    > Is the command concatenation "&&" correct at all?
    >
    > What if I want cmd2 only to execute if both (cmd1 and gzip) end
    > successfully?
    >
    > What about the other way: cmd2 should only be executed if
    >
    > a) cmd1 failed
    >
    > b) cmd1 or gzip failed?


    This is pretty trivial to test empirically on your own:

    $ true | false && echo foo
    $ false | true && echo foo
    foo
    $ true | true && echo foo
    foo
    $ false | false && echo foo
    $

    --
    _
    _V.-o Tristan Miller [en,(fr,de,ia)] >< Space is limited
    / |`-' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= <> In a haiku, so it's hard
    (7_\\ http://www.nothingisreal.com/ >< To finish what you

+ Reply to Thread