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?
$[] is a deprecated syntax for arithmetic expansion. It is thoroughly replaced by $(()) – chepner.
$() means: "first evaluate this, and then evaluate the rest of the line". Ex : echo $(pwd)/myFile.txt. will be interpreted as echo /my/path/myFile.txt. On the other hand ${} expands a variable.
<( Angle Parentheses ) Meaning that you can do things like: diff two streams. run a command within a shell to create an input-"file" for other commands that want input in the form of a file rather than a stream.
$1 means an input argument and -z means non-defined or empty. You're testing whether an input argument to the script was defined when running the script.
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 substitutionthe 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With