[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Problem around brackets, && and ||
From: |
Kunszt Árpád |
Subject: |
Problem around brackets, && and || |
Date: |
Mon, 03 May 2010 19:49:12 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100501 Thunderbird/3.0.4 |
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: x86_64-pc-linux-gnu-gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu'
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash'
-DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib
-DDEFAULT_PATH_VALUE='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
-DSTANDARD_UTILS_PATH='/bin:/usr/bin:/sbin:/usr/sbin'
-DSYS_BASHRC='/etc/bash/bashrc'
-DSYS_BASH_LOGOUT='/etc/bash/bash_logout' -DNON_INTERACTIVE_LOGIN_SHELLS
-DSSH_SOURCE_BASHRC -O2 -pipe -march=native
-mtune=native
uname output: Linux terminus 2.6.33-gentoo-syrius #1 SMP PREEMPT Fri Feb
26 15:57:48 CET 2010 x86_64 AMD Phenom(tm) 9500 Quad-Core Processor
AuthenticAMD GNU/Linux
Machine Type:
x86_64-pc-linux-gnu
Bash Version: 4.0
Patch Level: 37
Release Status: release
Description:
If the last command in a {...} has && and fails and the {...}
has an || outside then the outside command will be executed.
This happens not only for {...} but (...) too. I have to add ||
: to the last commands as workaround.
My English is very bad so I wrote some sample code to
demonstrate the problem, and the workaround. I can repeat this under
Bash version 3
too.
Repeat-By:
bad.sh:
#!/bin/bash
/bin/true && \
{
echo "I have to see this"
/bin/false && echo "I don't have to see this"
} || echo "I never have to see this!"
Outputs:
I have to see this
I never have to see this!
bad2.sh:
#!/bin/bash
/bin/true && \
(
echo "I have to see this"
/bin/false && echo "I don't have to see this"
) || echo "I never have to see this!"
Outputs:
I have to see this
I never have to see this!
good.sh:
#!/bin/bash
/bin/true && \
{
echo "I have to see this"
/bin/false && echo "I don't have to see this" || :
} || echo "I never have to see this!"
Outputs:
I have to see this
- Problem around brackets, && and ||,
Kunszt Árpád <=