Quotes in Bash

Quotes in Bash

Quotes in Bash

This is a standard practice to quote the string in any programming language. Quotes are used to deal with the texts, filenames with a space character. Read this tutorial to understand the differences between single quotes and double quotes.

Quote with String

While working with simple texts and strings, there are no differences in using a single quote or double quote.

The above script will run without any error and print the messages and create both directories.

Quote with Variables

Just remember that the shell variable expansion will work with double quotes only. If you define any variable in a single quote will not work.

#!/bin/bash

NAME="Welcome Test"

echo "$NAME"
echo '$NAME'

Now execute this script. The first echo will print the value of the variable ie “Welcome TecAdmin” " but the second variable will print only $NAME due to being enclosed in a single quote.

Reactions

Post a Comment

0 Comments

close