[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
increment & decrement error when variable is 0
From: |
Jetzer, Bill |
Subject: |
increment & decrement error when variable is 0 |
Date: |
Mon, 23 Nov 2020 19:36:29 +0000 |
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -march=x86-64 -mtune=generic -O2 -pipe
-fstack-protector-strong -fno-plt
-DDEFAULT_PATH_VALUE='/usr/local/sbin:/usr/local/bin:/usr/bin'
-DSTANDARD_UTILS_PATH='/usr/bin' -DSYS_BASHRC='/etc/bash.bashrc'
-DSYS_BASH_LOGOUT='/etc/bash.bash_logout' -DNON_INTERACTIVE_LOGIN_SHELLS
-Wno-parentheses -Wno-format-security
uname output: Linux ThinkTank 5.9.8-2-MANJARO #1 SMP PREEMPT Wed Nov 18
06:38:03 UTC 2020 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu
Bash Version: 5.0
Patch Level: 18
Release Status: release
Description:
The prefix and postfix versions of the increment (++) and
decrement (--) operators return a non-zero exist status when the varable's
value is zero. This causes scripts to terminate if `set -e` is used in scripts
(as in [bash strict
mode](http://redsymbol.net/articles/unofficial-bash-strict-mode/)). See [this
answer](https://stackoverflow.com/a/59775569/12859753) on Stack Overflow.
Repeat-By:
for ((i=-100; i<100; i++))
do
x=$i;
((--x)) || echo "err code $? on --x going from
$i to $x";
x=$i;
((x--)) || echo "err code $? on x-- going from
$i to $x";
x=$i;
((++x)) || echo "err code $? on ++x going from
$i to $x";
x=$i;
((x++)) || echo "err code $? on x++ going from
$i to $x";
done;
Results:
err code 1 on ++x going from -1 to 0
err code 1 on x-- going from 0 to -1
err code 1 on x++ going from 0 to 1
err code 1 on --x going from 1 to 0
CONFIDENTIAL : This transmission may contain information that is privileged,
confidential and/or exempt from disclosure under applicable law. If you are not
the intended recipient, you are hereby notified that any disclosure, copying,
distribution, or use of the information contained herein (including any
reliance thereon)is strictly prohibited. If you received this transmission in
error, please immediately contact the sender and destroy the material in its
entirety, whether in electronic or hard copy format.
- increment & decrement error when variable is 0,
Jetzer, Bill <=