Search code examples
shellenvironment-variablesquotes

Shell Quotations with and without environmental variables


Here is the question:

When the shell is reading the command-line, what is the difference between text enclosed between double quotes (") and text enclosed between single quotes (')?

You need to consider two cases in which there are environment variables and there are no environmental variables.

I can't seem to find a difference, to me both cases are used the same way.

I have a bit of an understanding of hard and soft quotes but this has thrown me.


Solution

  • Double quotes normally are used where Shell variable values can be extracted. Example:

    my_name="prabhu"
    echo "printing $my_name"
    

    Output: printing prabhu

    Single quotes does not print the value of a variable instead prints the given content. Example:

    my_name="prabhu"
    echo 'printing $my_name'
    

    Output: printing $my_name