🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #3991

Exit status of "if" statement?

#3991
From: Dan Stromberg
Date: Mon, 09 Apr 2012 17:31
20 lines
1895 bytes
What should be the behavior of the following?

if cmd1
then
    cmd2
fi && if cmd3
then
   cmd4
fi

I've not joined two if's with a short-circuit boolean before, but I'm
suddenly working on a script where someone else has.

Playing around, it appears that cmd1 and cmd3 have no direct impact on
the exit codes of the two if's, while cmd2 and cmd4 do (if cmd1 or
cmd3 evaluate true).  Is this the defined behavior in POSIX shell?  In
bash?  In bash symlinked to /bin/sh?  In dash?

TIA!
Technical Details
Message-ID: <3360b939-5d82-4258-90a2-58c2d5545943@pg2g2000pbb.googlegroups.com>
Path: arc1-ca.pugleaf.net!r9ni37284pbh.0!nntp.google.com!news2.google.com!postnews.google.com!pg2g2000pbb.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10038b,9538181a045179a4,start
X-Google-NewGroupId: yes
X-Google-Attributes: giddbda8d187b,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Received: by 10.68.236.170 with SMTP id uv10mr7758919pbc.4.1333992800336;
        Mon, 09 Apr 2012 10:33:20 -0700 (PDT)
Path: arc1-ca.pugleaf.net!r9ni37284pbh.0!nntp.google.com!news2.google.com!postnews.google.com!pg2g2000pbb.googlegroups.com!not-for-mail
From: Dan Stromberg <drsalists@gmail.com>
Newsgroups: comp.unix.shell,gnu.bash.bug
Subject: Exit status of "if" statement?
Date: Mon, 9 Apr 2012 10:31:36 -0700 (PDT)
Organization: http://groups.google.com
Lines: 22
Message-ID: <3360b939-5d82-4258-90a2-58c2d5545943@pg2g2000pbb.googlegroups.com>
NNTP-Posting-Host: 153.65.16.10
Mime-Version: 1.0
X-Trace: posting.google.com 1333992800 7919 127.0.0.1 (9 Apr 2012 17:33:20 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Mon, 9 Apr 2012 17:33:20 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: pg2g2000pbb.googlegroups.com; posting-host=153.65.16.10; posting-account=9hYMCAoAAAAYQqneyjRUiFwlGE-Cp-jx
User-Agent: G2/1.0
X-HTTP-Via: 1.1 cusxteradata2.td.teradata.com:80 (IronPort-WSA/7.1.3-021)
X-HTTP-UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML,
 like Gecko) Chrome/17.0.963.56 Safari/535.11,gzip(gfe)
Content-Type: text/plain; charset=ISO-8859-1