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?
Asked
Active
Viewed 1.7k times
29
-
5The 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
-
4I 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 Answers
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
-
15`$[]` is a deprecated syntax for arithmetic expansion. It is thoroughly replaced by `$(())` – chepner Aug 01 '13 at 11:49
-
4For a reference on $[ ] being obsoleted over $(( )) --- http://wiki.bash-hackers.org/scripting/obsolete – Loves Probability Jun 19 '16 at 12:48