Techniques cited in Unix / Linux

Shell provides a variety of characters that have special meaning while using them in any Shell script and cause a limit of a word unless quoted.

Super characters in Unix / Linux

Shell provides a variety of characters that have special meaning while using them in any Shell script and cause a limit of a word unless quoted.

For example: super characters? connect to a single character while listing files in a folder and super characters * will connect more than one character. The following lists a list of most special characters in the shell (also called super characters).

 * ? [ ] '"$; & () | ^ <> new-line space tab 

A character can be cited by preceding it with a sign.

Example in Unix / Linux:

Here is an example showing how to print a * or a?:

 #! / bin / sh echo Hello ; Word 

It will produce the following result:

 Hello ./ test . sh : line 2 : Word : command not found shell returned 127 

Now we use a quoted character:

 #! / bin / sh echo Hello ; Word 

It will produce results:

 Hello ; Word 

The $ symbol is a metaphor, so it must be cited to avoid the shell from performing special tasks related to it:

 #! / bin / sh echo "I have $ 1200" 

The above code produces the following result:

 I have $ 1200 

There are 4 types of citation patterns listed in the following table:

Quote Description of Single Quote All characters in the middle of this citation are no longer of special significance to the shell. Double quotes Most characters between this citation have no special meaning except the following characters:
  1. $
  2. `
  3. $
  4. '
  5. "
Backslash Any character behind the backslash does not have its special meaning. Reverse quote (``) Any character in the middle of a reverse quote is treated by the shell as a command and run.

Single quotes in Unix / Linux:

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' 

Double quotes in Unix / Linux

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' 

Quoted back in Unix / Linux

By placing any shell command in the middle of the citations, the shell will execute that command.

Syntax

This is a simple syntax for placing any Shel l command in the middle of a reverse quote:

For example:

 var = `command` 

For example:

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

5 ★ | 1 Vote