-
Notifications
You must be signed in to change notification settings - Fork 1.9k
SC3044
Eisuke Kawashima edited this page Jul 29, 2025
·
4 revisions
#!/bin/sh
declare var="value"or
#!/bin/sh
declare -r readonlyor
#!/bin/sh
declare ...If assigning a simple variable outside of a function, skip declare all together:
var="value"If declaring a variable read-only:
var=value
readonly varIf you are unable to find a suitable replacement, consider switching to a shell that supports declare:
#!/bin/bash
declare ...Indexed arrays, associative arrays, local variables, namerefs, and integer variables are not supported in POSIX sh. Either write around them, or switch to a shell that supports them.
The declare command is non-standard, and most of its functionality is not available across shells.
Either find a POSIX replacement, or switch to a shell that is guaranteed to support them.
If your declare command is guarded by a check of the shell version, such as inspecting $BASH_VERSION, you can ignore this message.
- Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!