SC3044 – ShellCheck Wiki

See this page on GitHub


In POSIX sh, declare is undefined.

Problematic code:

declare var="value"


declare -r readonly


declare ...

Correct code:

If assigning a simple variable outside of a function, skip declare all together:


If declaring a variable read-only:

readonly var

If you are unable to find a suitable replacement, consider switching to a shell that supports declare:

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.

ShellCheck is a static analysis tool for shell scripts. This page is part of its documentation.