Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

progress.sh: Avoid accidental early return #171

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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