Skip to content

Conversation

@karlb
Copy link

@karlb karlb commented Nov 12, 2024

expr returns a non-zero exit code if its calculated value is zero. This is surprising and usually not what you want. In this case, it will lead to the script terminating early for some values (e.g. HOURS=0). Small example to show the problem:

> bash -c 'HOURS=`expr 0` && echo true || echo false'
false

Fortunately, bash has the arithmetic calculation syntax $((...)) that behaves as intended.

expr returns a non-zero exit code if it's calculated value is zero. This
is surprising and usually not what you want. In this case, it will lead
to the script terminating early for some values (e.g. HOURS=0). Small
example to show the problem:

```
> bash -c 'HOURS=`expr 0` && echo true || echo false'
false
```

Fortunately, bash has the arithmetic calculation syntax $((...)) that
behaves as intended.
@karlb karlb changed the title progress: Avoid accidental early return progress.sh: Avoid accidental early return Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant