Escaping Characters in double quotes

To escape characters we can use \ before the character to parse it as it is. For example, you need to print the $ symbol you need type \$ to work as desired inside the double quotes. We have used \” to escape the double quotes and by that, we have used double quotes inside the double quotes. So, to parse the character without its special operations to perform we need to use \ to simply print it.

Back Quotes(Backticks):

In the previous section, we have used the backquotes to use the commands inside the double-quotes. The back quotes allow us to execute the commands inside a shell script, Not only they can be used inside the double quotes they can be used independently in the script.

#!/usr/bin/env bash

echo `python --version` 
echo `cat wh.txt`
echo `date`

Output:

As we can see here we can execute commands from the script. These are the commands which can be executed inside the command prompt, yes you can use certain commands like cat, pwd, etc as it is in the script but not all commands can be used as it is in the script. For executing those commands we can use the back quotes(` `). These can be also be nested in double-quotes as we saw earlier in the double quotes example.  

So these are the quoting techniques we use in the shell script to expand variables, execute commands and perform and execute other operations/scripts from a shell script. The quoting can be used for programming certain commands and executing/expanding them as and when required by embedding the commands in the appropriate quotes.


Bash Script – Quotes and its types

Quoting in bash scripting is a process to make variables or any other container for data to be expanded to the literal value inside any string, quoting is also used for other operations as well. There are several types of quoting techniques in a bash script. In this article, we will see the different types of quoting in Bash scripting.

Types of Quotes in BASH

  • Single Quotes
  • Double Quotes 
  • Back Quotes

Similar Reads

Single Quotes:

By using single quotes the string is parsed as it is without any expansion of characters inside the quotes. So, if we have a variable inside the string the value won’t be expanded instead the characters will be parsed as it is....

Double Quotes:

To expand the variable value inside a string we use the double-quotes. Using double quotes we can expand the literal value of the variable by just prefixing the variable name with $ as said earlier for accessing the value with the variable name....

Escaping Characters in double quotes

To escape characters we can use \ before the character to parse it as it is. For example, you need to print the $ symbol you need type \$ to work as desired inside the double quotes. We have used \” to escape the double quotes and by that, we have used double quotes inside the double quotes. So, to parse the character without its special operations to perform we need to use \ to simply print it....