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:
[ Parent
| on HN ]
I'm going to assume that if one is using [ rather than [[ then one will also want to use expr rather than $(()).
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.
Oh, I did not know that! Thanks.
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
Even better, and TIL. Thanks!