#-----------------------------------------------------------------------
# Intializing variables 
#-----------------------------------------------------------------------
#Rule 0: Unix variables can be drawn from [a-zA-z0-9_] but not start with a
#        a digit (why? because $1, $2 .. is reserved for positional paramters)
#Rule A: assignment is strictly as follows, a=1 (no blank space)
#Rule B: Usage of variable requires the variable to be preceded by $

$ a=1           #note: no space on either side of "="
$ echo $a       #no quoting at all. so simple expansion of variable 
1

$ a="1"         #double quoted not needed here
$ echo $a
1
$ HK="Hello Kitty"   #Need double quote since space is part of the variable
$ echo $HK
Hello Kitty

$ echo $b      #variable not sent; b=set to null variable.

	#Not so obvious 
$ echo "*"     #the character * is printed out
*

$ echo * 	 #standard interpretation of wildcard 
BasicUNIX.txt BraceExpansion.txt QuotingRules.txt a.dat b.dat echo.txt kitty tr.txt variables.txt xargs.txt

$ b=* 	            #or equally b="*"
$ echo $b           #interprets "*" as a special character

#------------------------------------------------------------------
# Quouting  Rules
#------------------------------------------------------------------

# Rule 1: Almost anything in between single quotes is not 
#        interpreted by the shell
# Rule 2: Variable expansion is permitted within double quotes
# Rule 3: The outer quote sets the quoting rules


#-------------------------------------------------------------------
#	Examples to understand single and double quotes
#-------------------------------------------------------------------

$ echo hello #no quoting. no meta-characters. print as it is
hello

$ echo "hello" 
hello

$ echo "\"hello\""	#in order to print double quotes
"hello"                 #escape it

$ echo "'echo'"         #outer quote is double. ' has no special
	                #meaning


$ echo "$a"     #within double quotes expansion takes place
1

$ echo  '$a'    #within single quotes there is no expansion (interpretation) 
$a

$ echo "'$a'"   #rules set by outer quote. here double quote rules apply
'1'

$ echo '"$a"'   #outer quote is a single. So single quote rules apply
"$a"            #no expansion allowed

$ echo \"$a\"   #No quoting. The double quote is escaped and so is printed.
"1"

$ echo \'$a\'   #No quoting. The single quote is escaped and so is printed.
'1'

$ echo "\"$a\"" #outer quote is a double. So expansion takes place
"1"             #double quote is escaped so it can be printed
                #$a is expanded since double quote rules apply

$ echo '\"$a\"\'  #single outer quote, so no expansion is allowed
\"$a\"

#-----------------------------------------------------------
#    Building up strings 
#-----------------------------------------------------------

$ a=Hello b=Kitty
$ echo $a $b
Hello Kitty

$ echo $a       $b       #No quoting; shell rules apply; >1 blank ignored
Hello Kitty

$ echo "$a    $b"       #Double quotes preserve blanks
Hello    Kitty

$ echo '$a $b'         #Single outer quote. So expansion
$a $b

$ echo "$a"" nice ""$b"  #as long there is no space each string is concatenated
Hello nice Kitty 

$ echo '$b'" is a nice ""$b"
$b is a nice Kitty

$ echo '$'"s/Kitty/Mitty"
$s/Kitty/Mitty