A note about quotes
Single quote: ‘ ‘ supresses all special characters.
root@bt:/# echo ‘$?’
$? is used to know the exit status, because $? is enclosed within a pair of single quotes all special meaning has been suppressed and printed out as it is.
Double quote: ” ” supresses most of the special characters except for $, \ and `.
If a single $ is enclosed within ” ” double quotes $ will still be printed as $ itself has no special meaning, however if $ is sub-ceded with other characters, numbers or symbols bash treated it with special meaning.
Example of single $ enclosed within double quotes:
root@bt:/# echo “$”
Example of $ sub-ceded with another character and enclosed within double quotes:
root@bt:/# echo “$?”
0 is the exit status, 0 means normal.
Another example of $ sub-ceded by another character:
root@bt:/# echo “$(ifconfig eth0)”
eth0 Link encap:Ethernet HWaddr e8:11:32:41:88:9d
inet addr:184.108.40.206 Bcast:220.127.116.11 Mask:255.255.255.0
inet6 addr: fe80::ea11:32ff:fe41:889d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:57864 errors:0 dropped:0 overruns:0 frame:0
TX packets:4520 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:11899324 (11.8 MB) TX bytes:615368 (615.3 KB)
Interrupt:41 Base address:0xe000
As you can see bash treated $ specially. However compare with another example using a pair of single quotes:
root@bt:/# echo ‘$(ifconfig eth0)’
I hope this illustration is clear enough, this is very important because while writing a bash script desired results might not be achieved due to the misused of quotes.