Skip to content
Vidar Holen edited this page Jan 21, 2015 · 10 revisions

Braces are required for positionals over 9, e.g. ${10}.

Problematic code:

echo "Ninth parameter: $9"
echo "Tenth parameter: $10"

Correct code:

echo "Ninth parameter: $9"
echo "Tenth parameter: ${10}"

Rationale:

For legacy reasons, $10 is interpreted as the variable $1 followed by the literal string 0.

Curly braces are needed to tell the shell that both digits are part of the parameter expansion.

Exceptions

If you wanted the trailing digits to be literal, ${1}0 will make this clear to both humans and shellcheck.

ShellCheck

Each individual ShellCheck warning has its own wiki page like SC1000. Use GitHub Wiki's "Pages" feature above to find a specific one, or see Checks.

Clone this wiki locally