-
Notifications
You must be signed in to change notification settings - Fork 1.8k
SC1037
Mingye Wang edited this page Aug 1, 2019
·
10 revisions
echo "Ninth parameter: $9"
echo "Tenth parameter: $10"
echo "Ninth parameter: $9"
echo "Tenth parameter: ${10}"
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.
If you wanted the trailing digits to be literal, ${1}0
will make this clear to both humans and shellcheck.
In dash
, $10
is (wrongly) interpreted as ${10}
, so some 'reversed' care should also be taken:
bash -c 'set a b c d e f g h i j; echo $10 ${1}0' # POSIX: a0 a0
dash -c 'set a b c d e f g h i j; echo $10 ${1}0' # WRONG: j a0
- BashFaq: How can I access positional parameters after $9?
- StackOverflow: How to handle more than 10 parameters in shell
- Autoconf Manual: Shell Substitutions - documents some non-POSIX older shells too