From 496c09573ae42e2dac6fa7fc71958f55748b9947 Mon Sep 17 00:00:00 2001 From: Lucas Larson <91468+LucasLarson@users.noreply.github.com> Date: Fri, 14 May 2021 20:25:29 -0400 Subject: [PATCH] =?UTF-8?q?create=20for=20documenting=20POSIX=20shell?= =?UTF-8?q?=E2=80=99s=20undefined=20standalone=20`((..))`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SC3006.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 SC3006.md diff --git a/SC3006.md b/SC3006.md new file mode 100644 index 0000000..4b8aed5 --- /dev/null +++ b/SC3006.md @@ -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 +``` \ No newline at end of file