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

Use (( )) instead of [[ ]]? #1

Open
dimitry-ishenko opened this issue Dec 21, 2022 · 2 comments
Open

Use (( )) instead of [[ ]]? #1

dimitry-ishenko opened this issue Dec 21, 2022 · 2 comments

Comments

@dimitry-ishenko
Copy link

(1) I see bash-utility heavily using

[[ $# -lt 2 ]] && ...

Wouldn't it be more readable to do

(( $# < 2 )) && ...

instead? (( is used for arithmetic evaluation, which is what -lt is trying to force inside [[.

(2) Also, seeing this:

[[ $# = 0 ]] && ...

rubs me the wrong way on multiple levels.

First, we are all taught that = is assignment and == is equivalence comparison. Yes, in bash they are the same when used inside [[, but = is used for assignment elsewhere in bash and IMHO this is just a bad coding practice.

Second, operator = within [[ is used for pattern matching and not arithmetic comparison. So, it should minimally be:

[[ $# -eq 0 ]] && ...

or better yet:

(( $# == 0 )) && ...

to be more readable and consistent with (1).

@labbots
Copy link
Owner

labbots commented Feb 7, 2023

Hi @dimitry-ishenko thanks for your feedbacks. I will update them when I get some time. In the meantime you could raise a PR with the recommended changes and I am happy to review them.

@dimitry-ishenko
Copy link
Author

Oh hey somebody is alive in here. 😃 I've made quite a few changes. Will send PR shortly

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

No branches or pull requests

2 participants