Bash script: Quotation explained with examples - JohnHau/mis GitHub Wiki

Quotation on a Linux system can be a source of confusion at first. Single quotes ' and double quotes " are treated differently in Bash, and you will need to know the difference if you are writing a Bash script.

In this tutorial, you will learn the difference between single quotes and double quotes. You will also see how to escape quotes in your Bash script. Follow along with our examples below to quickly master quotation in Bash.

In this tutorial you will learn:

How to use double quotes " in Bash scripting How to use single quotes ' in Bash scripting What is the difference between single quotes and double quotes? How to escape double quotes or single quotes

Bash script: Quotation explained with examples

image

image

image

Closing Thoughts In this tutorial, we saw how quotation works in a Bash script on Linux. The key takeaways are that variables are expanded inside of double quotes, but not inside of single quotes. Double quotes can be escaped using single quotes, and single quotes (as well as double quotes) can be escaped using backslashes. Now you will know which type of quotes to use in any situation.