Created
June 5, 2022 14:43
-
-
Save aprell/64959fc612ed63982f086c3165a6182d to your computer and use it in GitHub Desktop.
Be wary of arithmetic expressions when using `set -e`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
i=0 | |
while [ $i -lt 3 ]; do | |
r=$((RANDOM % 10)) | |
if [ $r -lt 3 ]; then | |
((i++)) | |
fi | |
done | |
echo "Done: i = $i" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use either
((++i))
ori=$((i + 1))
in this case. The reason: