How to use double quotes in Bash Shell Script?

There are three quote characters in bash shell: double quote("), single quote(') and backslash(\). In this tutorial, we will take a look at double quotes.

Double quotes work similarly to single quotes except there are some fewer restrictions. Following are the three special characters that are not ignored inside double quotes: dollar sign($), backquotes(`) and backslash(\).

echo "<>(){}>>&*|"



Unlike single quotes, if you try to access the value of variable inside double quotes, then you will able to access it.

echo '$double'
echo "$double"



You can even use double quotes when you are passing command-line arguments to a command.

$grep "Mohit Natani" students.txt


students.txt:S001 | Mohit Natani | Computer Science | 98%

Also, all the white spaces enclosed within double quotes are preserved by the shell.

echo bash      shell       scripting
echo "bash      shell       scripting"


bash shell scripting
bash      shell       scripting

Recommended Posts