You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Lucas Larson edited this page Mar 31, 2021
·
1 revision
In POSIX sh, exponentials are undefined.
Problematic code:
ShellCheck noticed you're using **-notation with two asterisks to obtain an exponent's value. Some examples:
#!/bin/shecho$((2**3))# Using `**` for an exponent is undefined in POSIX sh.
Correct code:
Other possibilities exist:
#!/bin/shecho$((2*2*2))# equivalent to `bash`'s `echo $((2 ** 3))`echo'2 ^ 3'| bc # piping the formula to `bc` to parse the output https://stackoverflow.com/a/13111995printf'2 ^ 3\n'| bc # piping using `printf` (newline `\n` is mandatory)
Help by adding links to BashFAQ, StackOverflow, man pages, POSIX!