I saw this Stack Overflow question regarding the use of parentheses in bash.
Great piece of information but I still have a couple of doubts about how to use parentheses. For instance the below code :
#!/bin/bash
a=5
b=6
c=7
$(( d = a * b + c ))
echo "d : "$d
gave me the output :
./parantheses: line 5: 37: command not found
d : 37
and my research about $(( ))
lead me to this site which gave me below piece of information.
$(( expression ))
The expression is treated as if it were within double quotes, but a double quote inside the parentheses is not treated specially. All tokens in the expression undergo parameter expansion, command substitution, and quote removal. Arithmetic substitutions can be nested.
I didn't quite get it :(
But I did understand that we don't have to use $
before every variable and that the variables will automatically be substituted. What more is to it and why my script is throwing an error?
Also what does a=$( expression )
do?
Does this one too work like $(( ))
?
Kindly illustrate the answers with examples so that I can understand better.
Note : I ran the above script in cygwin.