mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
create for documenting POSIX shell’s undefined standalone ((..))
23
SC3006.md
Normal file
23
SC3006.md
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
## In POSIX sh, standalone ((..)) is undefined.
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
variable=1
|
||||||
|
if ((variable)); then
|
||||||
|
echo variable is not zero
|
||||||
|
fi
|
||||||
|
```
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
[`bash` supports standalone `((..))`](https://www.gnu.org/software/bash/manual/html_node/Conditional-Constructs.html#index-select) natively.
|
||||||
|
|
||||||
|
For POSIX compliance, use
|
||||||
|
|
||||||
|
```sh
|
||||||
|
variable=1
|
||||||
|
if [ "${variable}" -ne 0 ]; then
|
||||||
|
echo variable is not zero
|
||||||
|
fi
|
||||||
|
```
|
Reference in New Issue
Block a user