29

Bash contains different braces and they used differently. Could you please explain comprehensively what is difference between ${}, $() and $[]? Where they are used in bash? What is their main purpose?

samayo
  • 16,163
  • 12
  • 91
  • 106
yart
  • 7,515
  • 12
  • 37
  • 37
  • 5
    The proposed duplicate doesn't really cover the use of the various brackets with the dollar sign, though. It's more about `[]`, `[[]]`, `{}`, and `()`, with `${}` thrown in. – chepner Aug 01 '13 at 11:51
  • 4
    I came here looking to learn what `$[ ]` is. This questions asks exactly that and the dupe does not answer it. – chutz Oct 14 '15 at 00:42

1 Answers1

20

The keyword is shell expansion! So i highly recommend you to read the section Shell Expansions in your bash reference manual.

You can access this section online [1].

The names of the following stated forms are:

  • ${} Parameter expansion
  • $() Command substitution

the form $[] isn't actually stated in the manual so i wouldn't use it.

[1] http://www.gnu.org/software/bash/manual/bashref.html#Shell-Expansions

user1146332
  • 2,630
  • 1
  • 15
  • 19