{"thread":{"id":"38940","subject":"[question] && chaining vs shell loops","startedAt":"2015-03-29T15:48:41Z","lastAt":"2015-03-30T06:29:25Z","messageCount":4,"participants":["Max Kirillov","Andreas Schwab","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"258656","messageId":"20150329154840.GA8771@wheezy.local","threadId":"38940","inReplyTo":null,"subject":"[question] && chaining vs shell loops","fromName":"Max Kirillov","fromEmail":"max@max630.net","sentAt":"2015-03-29T15:48:41Z","receivedAt":"2015-03-29T15:48:41Z","isPatch":false,"sender":{"key":"max@max630.net","avatar":"https://avatars.githubusercontent.com/u/381560?v=4"},"body":"Hi.\n\nAs far as I can see, loops in shell ignore non-zero exit\ncodes of the bodies which are not last. For example, exit\ncode of command 'for f in false true; do $f; done' is 0,\neven if there was false.\n\nHow should one workaround it in test scripts, is there any\nestablished approach?\n\n-- \nMax\n"},{"id":"258658","messageId":"874mp3948k.fsf@igel.home","threadId":"38940","inReplyTo":"20150329154840.GA8771@wheezy.local","subject":"Re: [question] && chaining vs shell loops","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2015-03-29T16:07:39Z","receivedAt":"2015-03-29T16:07:39Z","isPatch":false,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"Max Kirillov <max@max630.net> writes:\n\n> As far as I can see, loops in shell ignore non-zero exit\n> codes of the bodies which are not last. For example, exit\n> code of command 'for f in false true; do $f; done' is 0,\n> even if there was false.\n\nThere is nothing special with loops, that's how the exit code of\ncompound commands is defined in general: it's the exit code of the last\nexecuted command.\n\nAndreas.\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5\n\"And now for something completely different.\"\n"},{"id":"258660","messageId":"20150329174312.GA6680@peff.net","threadId":"38940","inReplyTo":"874mp3948k.fsf@igel.home","subject":"Re: [question] && chaining vs shell loops","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-03-29T17:43:13Z","receivedAt":"2015-03-29T17:43:13Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Mar 29, 2015 at 06:07:39PM +0200, Andreas Schwab wrote:\n\n> Max Kirillov <max@max630.net> writes:\n> \n> > As far as I can see, loops in shell ignore non-zero exit\n> > codes of the bodies which are not last. For example, exit\n> > code of command 'for f in false true; do $f; done' is 0,\n> > even if there was false.\n> \n> There is nothing special with loops, that's how the exit code of\n> compound commands is defined in general: it's the exit code of the last\n> executed command.\n\nYes, but that makes it problematic if you want to know if any of the\nloop iterations failed. Doing:\n\n  for f in false true; do $f || break; done\n\ndoesn't work, because the \"break\" has exit code 0. Doing:\n\n  (for f in false true; do $f || exit 1; done)\n\nworks. In our test scripts, it is also OK to just \"return 1\", because\nthe test snippets execute inside a function.\n\nIf you have other solutions, I'd love to hear them. I just fixed several\nof these loops recently, and I couldn't come up with anything more\nclever.\n\n-Peff\n"},{"id":"258666","messageId":"CAF7_NFTxg3y9gWqHQqgt_TmOfUxA7yH2Krn4ma8SoY_-1Gx4SQ@mail.gmail.com","threadId":"38940","inReplyTo":"20150329174312.GA6680@peff.net","subject":"Re: [question] && chaining vs shell loops","fromName":"Max Kirillov","fromEmail":"max@max630.net","sentAt":"2015-03-30T06:29:25Z","receivedAt":"2015-03-30T06:29:25Z","isPatch":false,"sender":{"key":"max@max630.net","avatar":"https://avatars.githubusercontent.com/u/381560?v=4"},"body":"On Sun, Mar 29, 2015 at 8:43 PM, Jeff King <peff@peff.net> wrote:\n> In our test scripts, it is also OK to just \"return 1\", because\n> the test snippets execute inside a function.\n\nThanks, sounds like a plan.\n\n-- \nMax\n"}]}