Altin Ukshini
Altin Ukshini

Reputation: 235

what's the difference of echoing the variables in this way?

What is the difference of echoing these variable in bash scripting?

EXAMPLE:

I declare a variable

VARIABLE="Hello World"

echo $VARIABLE

What's the difference between the one above and this below?

echo ${VARIABLE}

Does it make a difference if I put {} or not?

Upvotes: 1

Views: 69

Answers (1)

bilash.saha
bilash.saha

Reputation: 7316

No difference in your code

The curly braces, To delimiting a variable name are used for parameter expansion so you can do things like

Truncate a variable' content

$ var="abcde"; echo ${var%e*}
abcd

Make substitutions similar to sed

$ var="abcde"; echo ${var/e/1}
abcd1

Braces can also be useful when the expansion occurs in certain contexts. For example:

FOO=bar
echo $FOO1    # tries to print the value of a variable named "FOO1"
echo ${FOO}1  # prints "bar1"

Upvotes: 4

Related Questions