To be slightly more precise, the
$ is used to designate parameter
expansion. When you want to use the contents of a variable or the results of a command substitution in your script, you add the $ to the front of it.
Variable names themselves can only consist of letters, numbers, and underscores. This is different from languages like perl or php, where the variable names themselves start with dollar signs or other characters.
Code:
# example of variable expansion:
> foo="hello world" #set the variable named "foo" to the value of "hello world"
> echo "$foo" # expand and print the contents of foo
hello world
# example of command substitution "$(..)":
> file -i foo.txt # this is the output of the file command
foo.txt: text/plain; charset=us-ascii
> foo="$( file foo.txt | sed 's/.*=//' )" #set variable "foo" to the output of file,
#filtered through sed to strip off all
#but the last section.
> echo "$foo"
us-ascii
If you really want to learn about shell scripting, read through the BashGuide. It covers all the basic concepts:
http://mywiki.wooledge.org/BashGuide