Difference Between Single and Double Quotes in Bash

The difference is that:

Single quotes won’t interpolate anything, but double quotes will (e.g., variables, backticks, \ escapes), see the following examples:

Single and Double Quotes Difference for Bash Varable

The bash script:

#!/bin/sh

VAR=bash_variable

echo 'single quotes of bash variable:$VAR'
echo "double quotes of bash variable:$VAR"

The result:

single quotes of bash variable:$VAR  
double quotes of bash variable:bash_variable

Single and Double Quotes Difference for Backticks

The bash script:

#!/bin/sh

echo 'single quotes of backticks `uname`'

echo "double quotes of backticks `uname`"

The result:

single quotes of backticks `uname`

double quotes of backticks Linux

Single and Double Quotes Difference for Backslash

The bash script:

#!/bin/sh

echo 'single quotes of backslash \\ ?'
echo "double quotes of backslash \\ ?"

The result:

single quotes of backslash \\ ?  
double quotes of backslash \ ?

BTW, PHP quotes have the same behavior regarding with variable interpretation.

Written on August 16, 2015