Single versus double quotes in BASH


Understanding the difference between double versus single quotes is important when using BASH. Many times you may have seen them being used interchangeably. The basic difference is that variable names will be expanded within double quotes but not within single ones.

This example shows the normal output with no quotes.

As you can see the shell will expand the variable.

In this example we will surround the variable with double quotes.

We see the same result as before.

This time with single quotes.

The variable name is not expanded.

Here is another interesting case. The single quotes are inside the double quotes.

The variable is expanded and the single quotes are retained.

Here I flip the order with the single quotes on the outside.

The variable is not expanded but the double quotes are retained.

  • sudopeople

    A couple more interesting cases:

    echo \”$USER’\’

    echo “‘”‘$USER'”‘”