What is the difference between:

./script.sh "$VARIABLE"


./script.sh ${VARIABLE}

Is there any?


$VARIABLE and ${VARIABLE} are effectively the same if they are standalone words. But notice the following example, especially in a script


you get output


but when you type


expecting to get


you get nothing as there is no variable as VARIABLE1 defined

But if you use

echo ${VARIABLE}1

you get the expected USER1 output.

| improve this answer | |

from Shawn J. Goff: $VAR vs ${VAR} and to quote or not to quote

VAR=$VAR1 is a simplified version of VAR=${VAR1}. There are things the second can do that the first can't, for instance reference an array index (not portable) or remove a substring (POSIX-portable). See the More on variables section of the Bash Guide for Beginners and Parameter Expansion in the POSIX spec.

Using quotes around a variable as in rm -- "$VAR1" or rm -- "${VAR}" is a good idea. This makes the contents of the variable an atomic unit. If the variable value contains blanks (well, characters in the $IFS special variable, blanks by default) or globbing characters and you don't quote it, then each word is considered for filename generation (globbing) whose expansion makes as many arguments to whatever you're doing.

| improve this answer | |
  • When you copy someone else's text, you need to clearly mark it as having been copied by using quotation markup. But don't copy someone else's answer on the same site, it's pointless: instead, flag the question to close it as a duplicate. – Gilles 'SO- stop being evil' Jun 21 '16 at 23:23
  • @Gilles: As provided from your link: When you find a useful resource that can help answer a question (from another site or in an answer on Unix & Linux Stack Exchange) make sure you do all of the following: Provide a link to the original page or answer Quote only the relevant portion Provide the name of the original author – igiannak Jun 22 '16 at 6:46
  • 1
    But when the questions are the same, don't do that. Instead, we have a mechanism for saying “this question is the same as another one so go and see the answers there”. – Gilles 'SO- stop being evil' Jun 22 '16 at 7:05

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