0

This question already has an answer here:

What is the difference between:

./script.sh "$VARIABLE"

and

./script.sh ${VARIABLE}

Is there any?

marked as duplicate by Gilles bash Jun 21 '16 at 23:20

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

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

VARIABLE=USER
echo $VARIABLE

you get output

USER

but when you type

echo $VARIABLE1

expecting to get

USER1

you get nothing as there is no variable as VARIABLE1 defined

But if you use

echo ${VARIABLE}1

you get the expected USER1 output.

0

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.

  • 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 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 – GiannakopoulosJ 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 Jun 22 '16 at 7:05

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