News for hackers. Stuff that matters.
Re:Test, [, and [[ (2020) by darrenf on Thursday November 23, 2023 @05:40AM (#38391387)
Regardless of `-a` vs two tests and `&&`, there's no need to shell out to `expr` if bash's arithmetic evaluation is available:

    [ $((1+1)) -eq 2 ]
Re:Test, [, and [[ (2020) by kqr on Thursday November 23, 2023 @06:11AM (#38391565)
I'm going to assume that if one is using [ rather than [[ then one will also want to use expr rather than $(()).
Re:Test, [, and [[ (2020) by ykonstant on Thursday November 23, 2023 @06:29AM (#38391668)
Arithmetic expansion is a feature of all POSIX compliant shells, which furthermore advises against using `expr`. The latter is only needed for non-compliant shells like some legacy implementations of the Bourne shell.
Re:Test, [, and [[ (2020) by kqr on Friday November 24, 2023 @03:05AM (#38401618)
Oh, I did not know that! Thanks.
Re:Test, [, and [[ (2020) by darrenf on Thursday November 23, 2023 @06:52AM (#38391780)
What's the basis for that assumption? I'm struggling to see a reason to not use the shell for arithmetic, regardless of `/usr/bin/[`, builtin `[` or `[[`.
Re:Test, [, and [[ (2020) by neuromanser on Thursday November 23, 2023 @09:50AM (#38393314)
arithmetic evaluation is ((…)), $((…)) is arithmetic expansion.

There’s no need for test(1) / [(1) or conditional expressions ([[…]]) if you’re doing arithmetic:

if ((1+1 == 2)); then …; fi

Re:Test, [, and [[ (2020) by darrenf on Thursday November 23, 2023 @10:47AM (#38394015)
Even better, and TIL. Thanks!
Re:Test, [, and [[ (2020) by Too on Thursday November 23, 2023 @01:16PM (#38395727)
The fact that seasoned developers have to discuss how to write 1+1 correctly, says everything you need to know about the language.