-
Notifications
You must be signed in to change notification settings - Fork 1.8k
SC3028
Lawrence Velázquez edited this page May 21, 2023
·
3 revisions
(or "In dash, ... is not supported." when using dash
)
#!/bin/sh
echo "$HOSTNAME $UID $RANDOM"
Either switch to a shell like bash
that supports the special variable you're trying to use, or use an external command to get the information you want:
#!/bin/sh
echo "$(hostname) $(id -u) $(awk 'BEGIN { srand(); print int(rand()*32768) }' /dev/null)"
The variable you are attempting to use is a special variable in bash or ksh. To get the same information from dash
or POSIX sh
, use an external command instead.
For PIPESTATUS
, the pipeline can be instrumented to record the exit value of each command:
{ cmd0; echo $? > status0; } | { cmd1; echo $? > status1; } | cmd2
If you only intend to target shells that support this feature, you can change the shebang to a shell that guarantees support, or ignore this warning.
You can use # shellcheck disable=SC3000-SC4000
to ignore all such compatibility
warnings.
- Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!