We consider an echo command that contains many special characters in the following shell:
echo <- $ 1500. **>; ( update ?) [ y | n ]
Putting a backslash () in front of every special character is tedious and makes the code difficult to read.
echo < - $ 1500 . **>; (update?) [y | n]
There is an easy way to quote a large group of characters. We place a single citation (`) at the beginning and end of the string:
echo '; (update?) [y | n] '
Any character in a single citation is quoted as having a backslash before each character. Therefore, now each echo command is displayed correctly.
If a single citation appears in a string to create the output, you should not place the entire string in the single citation, instead you should precede them with the following:
echo 'It's Shell Programming'
You are trying to run Shell script later. This script uses single quotes:
VAR = ZARA echo '$ VAR owes ; [as of (`date +% m /% d`)] '
It will produce the following result:
$ VAR owes <- $ 1500. **>; [ as of ( `date +% m /% d` ) ]
But it's not what you want to display. So it is clear that a single quote prevents the variable replacement. If you want to replace the value of the variable and perform the following comma as you would expect, then you need to place your commands in the double quote as follows:
VAR = ZARA echo "$ VAR owes ; [as of (` date +% m /% d`)] "
It will produce the following result:
ZARA owes <- $ 1500. **>; [ as of ( 07/02 ) ]
Double quotes eliminate the special meaning of all special characters except the following:
$ for parameter substitution
Reverse quote for command replacement
$ is represented by the letter of the dollar sign
`represents in words of reverse quotation marks
"allows embedded double quotes
Allows embedded backslash characters
All other "characters" are represented by its literal meaning (not specifically)
Any character in a single citation is cited as a backslash in the preceding section of each character. So now this echo command is displayed correctly.
If a single citation appears in a string in the output, you should not place the entire string in a single citation, but instead you should put it backwards as follows:
echo 'It's Shell Programming'
By placing any shell command in the middle of the citations, the shell will execute that command.
This is a simple syntax for placing any Shel l command in the middle of a reverse quote:
var = `command`
Here we will run the date command and keep the result in the DATA variable:
DATE = `date` echo " Current Date: $ DATE "
It results in:
Current Date : Thu Jul 2 05:28 : 45 MST 2009
According to Tutorialspoint
Previous article: Shell replacement
Next article: Navigation IO in Unix / Linux