Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

i have seen in many script usage of "$var" and "${var}", so I just want to know diffrence between "$var" and "${var}"

share|improve this question

marked as duplicate by manatwork, rush, jasonwryan, l0b0, camh Feb 13 '13 at 10:29

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.

The braces explicitly denote the beginning and end of the parameter syntax, otherwise, there is no difference. This makes certain statements unambiguous, for example:

$ foo=bar
$ echo "$fooa" # Is this $foo + a, or $fooa?

$ echo "${foo}a"
share|improve this answer
but i can use echo "$foo"a then why braces in used? – Rahul Patil Feb 13 '13 at 8:18
@RahulPatil Then there is no difference. " is an illegal character in a variable name, so it terminates there. – Chris Down Feb 13 '13 at 8:23
@RahulPatil But, with the braces you can do a lot more! See also the link provided by manatwork in the comment to your question. – Bernhard Feb 13 '13 at 8:55
There's no ambiguity in the first statement - It's clearly the value of the fooa variable. Bash is not DWIM-compatible :) – l0b0 Feb 13 '13 at 9:17
@l0b0 - perhaps I should have said "ambiguous to humans", obviously the actual syntax is defined ;-) – Chris Down Feb 13 '13 at 9:23

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