I see a lot of ${VARIABLE} type syntax in scripts. What is the point of the braces?
|
feedback
|
|
It delimits the variable. You might need $FOO as a variable, but need to concat it with other text. If so, this won't work:
This will complain that there's no variable $FOObar. To get around this, delimit the variable:
This will work, and print the value of $FOO with the text 'bar' concatenated. It's one of those things that people often choose to do all the time, to avoid problems where it's really required. It might be a good habit to get into, as bash scripting is very unforgiving of syntax mistakes. | |||
|
feedback
|
|
@mauvedeity is correct. The issue isn't just that some characters, when written after a variable reference are considered part of that reference — it's also that some characters are then considered to not be part of it. This breaks for example variable manipulating operations and use of arrays. Arrays:
Variable operations
All of this would fail (as illustrated in the array example) if we didn't explicitly set the delimiters for the variable reference. | |||
|
feedback
|