Path: csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: Uriel Newsgroups: gnu.bash.bug Subject: Conditions with logical operators and nested groups execute "if" and "else" Date: Mon, 21 May 2018 16:17:18 -0500 Lines: 86 Approved: bug-bash@gnu.org Message-ID: NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Trace: usenet.stanford.edu 1526969874 15250 208.118.235.17 (22 May 2018 06:17:54 GMT) X-Complaints-To: action@cs.stanford.edu To: bug-bash@gnu.org, bash@packages.debian.org Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=bvuWwhw1BkTki4buU9qbqMomZ0v+OXu/V9t/0aTNG30=; b=JE7d/WN1PXXHR3pvEwtachpdXjCfpG0NIU71JbSlHBMNSqlhzEb8FLWB7QLSAP8H/p KrCdBQ1LZvZDEcNGCddMz37DmoNQnJQW2DDAms/mniF9mfsyhwu7iSXq04yGE6TG6+4h ozkHKH+LJQLKn7TMkmDMp2tvRn8iHVeVv0dtUcq7wFeS2V2xgFoYE70bxCr0dHh9Mod2 +udBwmoIkNp6DhiAJ2lgQ/AAQgQBP1dWYq0ZsVOm951qTscsZ7DMT4Y5+ibe8Pem3L1L oWPDWtfFNxcnZopcNp9gb4vAkUY2UH64tsku2gx+HPi7qst0vvrOFyaztTp7VAsBlKJC CYgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=bvuWwhw1BkTki4buU9qbqMomZ0v+OXu/V9t/0aTNG30=; b=nFzTv9qRed4ooC+7RruQsiHS4HdIhIKTYjjMkOy3hSCe57bbR7H0cKmx/t3w1PZyHp mDX3099DjKPpaiGFGJr6nsrSWVY+ey7Ieog5z4eaL2wsi/cjrcK1nOQ5l0Mx+kYM3LJK uu+67rR3EavbjOfgtbMaBNVbQX+SPGNNSqCP2L2fPP6/1jOS1d9f6nqEZzA0EhNyw+Wr WPZ67LnwOdAuhPehlQbr8vR8kkZPJmXt5fS5foz7fBFPrLfp5bctJ/2GuwviWLp9wGPl E/1y8S6JDjSDuCxC+ozTfZgUZnPfBznTX6jM2qd3Wvhd3xUigvLdaSCUVN8CnxvkkgL1 +pyg== X-Gm-Message-State: ALKqPwcbh6jnLhfvzu1gtTUC9rBLFnn56RSzUpiXeNdHNj0cg67sqSPT 49GWdxuIvBzs/Jt8DgTWtRb8ZOZ1J/2MCGNdEmo= X-Google-Smtp-Source: AB8JxZowThwRPq6ZiLtsm6pjxPfeFZWJ2cuny5dKUONpEX+l/AwJ5IfpA10kT234DuiwndRkpLB16+m++lIKU6OuIP4= X-Received: by 2002:a6b:6b02:: with SMTP id g2-v6mr24071292ioc.250.1526937451231; Mon, 21 May 2018 14:17:31 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c06::233 X-Mailman-Approved-At: Tue, 22 May 2018 02:17:53 -0400 X-Content-Filtered-By: Mailman/MimeDel 2.1.21 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:14125 Configuration Information: Machine: x86_64 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM=3D'bash' -DCONF_HOSTTYPE=3D'x86_64' -DCONF_OSTYPE=3D'linux-gnu' -DCONF_MACHTYPE=3D'x86_64-pc-linux-gnu' -DCONF_VENDOR=3D'pc' -DLOCALEDIR=3D'/usr/share/locale' -DPACKAGE=3D'bash' -= DSHELL -DHAVE_CONFIG_H -I. -I../. -I.././include -I.././lib -Wdate-time -D_FORTIFY_SOURCE=3D2 -g -O2 -fdebug-prefix-map=3D/build/bash-DWMIDv/bash-4.4.18=3D. -fstack-protector-strong -Wformat -Werror=3Dformat-security -Wall -Wno-parentheses -Wno-format-security uname output: Linux HPgS 4.9.0-6-amd64 #1 SMP Debian 4.9.88-1+deb9u1 (2018-05-07) x86_64 GNU/Linux Machine Type: x86_64-pc-linux-gnu Bash Version: 4.4 Patch Level: 19 Release Status: release Description: As you know, a conditional is of the type: if [[ EXPRESSION ]]; then TRUE CONDITION; else ALTERNATIVE RESULT; fi Or with logical operators and groups: [[ EXPRESSION ]]; && { TRUE CONDITION; } || { ALTERNATIVE RESULT; } Within each of the conditionals there may be more nested, written the first or second way they should give the same result, however, using the logical operators form to obfuscate the code a little, I find that my conditional (which has another one in it) is executed in the first condition and also in the second one. Analyzing for a long time if it was a mistake in rewriting I sa= w that it worked the same way, the problem seems to be one of the operator =C2=AB!=C2=BB in a =C2=AB=3D~=C2=BB conditional because when testing this same notation with= other conditions it does not seem to have an error. Repeat-By: #!/bin/bash # In the second example passing through =C2=AB[[ ! "$OPT" =3D~ ^- ]] && { OPT=3D"-$OPT"; }=C2=BB should end, however, it continues with the following OPT=3D"-e-e-e--debug"; OPT_PERFECT=3D"-e" echo "INICIAL $OPT" if [[ "$OPT" =3D~ ^- ]]; then OPT=3D"${OPT#$OPT_PERFECT}" echo "REDUCCION TIPO 1 $OPT" if [[ ! "$OPT" =3D~ ^- ]]; then OPT=3D"-$OPT" echo "CONDICIONAL $OPT" fi else OPT=3D"${OPT#$OPT_PERFECT}" echo "REDUCCION TIPO 2 $OPT" fi echo "----------------------------------------------" OPT=3D"-e-e-e--debug"; OPT_PERFECT=3D"-e" echo "INICIAL $OPT" [[ "$OPT" =3D~ ^- ]] && { OPT=3D"${OPT#$OPT_PERFECT}" echo "REDUCCION TIPO 1 $OPT" [[ ! "$OPT" =3D~ ^- ]] && { OPT=3D"-$OPT" } } || { OPT=3D"${OPT#$OPT_PERFECT}" echo "REDUCCION TIPO 2 $OPT" } Fix: No big deal, you can use operator alternatives instead of =C2=AB[[ ! "$OPT" =3D~ ^- ]] && { OPT=3D"-$OPT"; }=C2=BB you can use =C2=AB[[ "$OPT" =3D~ ^- ]] || { OPT=3D"-$OPT"; }=C2=BB.