Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there a difference when variables are referred to as $variableName and ${variableName} in bash?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

From man bash:

The basic form of parameter expansion is ${parameter}. The value
of parameter is substituted. The braces are required when
parameter is a positional parameter with more than one digit, or
when parameter is followed by a character that is not to be
interpreted as part of its name.

Examples:

echo ${10}
foo=bar
echo ${foo}bar
share|improve this answer
    
+1 They're also required when referring to an array element that's not on the left hand side of an assignment. In fact they are never used on the left hand side. For scalar variables where there's no following characters that need to be set apart, the braces are optional. var=$other is equivalent to var=${other}. –  Dennis Williamson Sep 13 '10 at 15:52
1  
barbar? (6more) –  VxJasonxV Sep 13 '10 at 16:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.