Javatpoint Logo
Javatpoint Logo

Quotes in Bash

In this topic, we will learn to use quotes in Bash Scripts. When we want variables to store more complex values, we need to make use of quotes. Quotes are used to handle texts and filenames with a space character. It is because Bash uses a space to determine separate items.

When we enclose our contents in quotes, we are indicating to Bash that the content within the quotes should be considered as a single item. Read the following tutorial to understand how to use a single quote or double quote:

Quote with String

While working with simple texts and string, there will be no differences either we use a single quote or double quote.

Check out the example below:

Bash Script

Bash Console View

Above script will look like the following image in the Bash console:

Quotes in Bash

Output

Quotes in Bash

The above script will run without any error and provide the output as shown here.

Quote with Variable

It should be noted that the shell variable expansion will only work with double-quotes. If you define any variable in single quotes, then it will not be considered as a variable. Let's understand this with an example:

Bash Script

Bash Console View

Above script will look like the following image in the Bash console:

Quotes in Bash

Output

Quotes in Bash

Here, the first echo will provide the output value of a variable, i.e., "Hello, Welcome at Javatpoint". But the second echo will provide the output value as $name because it is enclosed in single quotes.

Example of Quote

Check out the example below to understand the concept of quotes more clearly:

Bash Script

Bash Console View

Above script will look like the following image in the Bash console:

Quotes in Bash

Output

Quotes in Bash

Conclusion

In this topic, we have discussed how to use quotes in Bash Script file.


Next TopicBash Variables




Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA