10 February 2012

Different Type of Quotes in Linux/Unix.

2 comments

Different Type of Quotes in Linux/Unix


There are mainly four types of quotes characters used in Linux , These are

1. " (double quote)
2. ' (single quote)
3. ` (back quote)
4. \ (back slash)

Lets see the usage of each one in detail

Back Quote

What ever enclosed between back-quote(` `) , shell interpret it as "output of the command inside the back-quote" This is known as Command Substitution . This can also be used to assign output of a command to a variable.

Lets say you want to count the number character , words and lines in a file which is entered by you.

$ cat > shell2.sh
#!/bin/bash
echo -e "The name of the file is\n" $1
echo " "
#notice the use of backquote
echo -e " The content of the $1 is\n `cat $1` \n"
echo " "
echo " No of character in $1 is :" `cat $1 | wc -c`
echo " "
echo "No of line in the $1 is : `cat $1 | wc -l` "
echo " "
echo "No of words in $1 is : `cat $1 | wc -w` "

Output



Another Example


Single quote and Double Quote (Similarity)

1. Anything which is enclosed between single and double quote can be treated as single string.They are useful ,if you need to refer to a file that has spaces in its name.


2.  Both suppress the meaning of wild-cards.





Single quote and Double Quote (Difference)

1. The basic difference between single quote and double quote is that single quote does not perform any kind of substitution i.e that is what ever written inside single quote is simply a string whereas double quote allow substitution.

a. Double quote expands the word begin with $ .


b. Command Substitution can be performed using double quotes i.e Back quote can be used within double quotes.



Back Slash

Backslash tells shell to "ignore next character."


By using \ shell ignores "$" and did not perform substitution on $HOSTNAME.

* Back slash can also be used to suppress the meaning of wild cards.






If You Liked This Post Please Take a Time To Share This Post

You May Also Like...

2 comments: