Description of quotation marks in shell programming

Source: Internet
Author: User
Tags echo command

There are many things worth learning about shell programming. Here we mainly introduce the quotation marks in shell programming, including introduction to shell programming. In shell programming, there are three types of quotation marks: single quotation marks, double quotation marks, and reverse quotation marks.

Single quote'

Shell programming contains all the characters enclosed by single quotes as common characters. When special characters are enclosed in single quotes, they will also lose their original meaning and will only be interpreted as common characters. For example:
$ String = '$ Path'
$ Echo $ string
$ PATH
$
It can be seen that $ retains its meaning and appears as a common character.

Double quotation marks

Characters enclosed by double quotation marks, except the characters $, ', and' are still special characters and keep their special functions. Other characters are still treated as common characters. For $, it is to replace this variable and $ with the variable value specified later. For, it is an escape character, it tells shell programming not to perform special processing on the character after it, just as a common character. You can imagine that the double quotation marks must be preceded by only four characters $, ', and. If no signature is added before the signature, Shell matches the signature with the previous signature.
For example, assume that the PATH value is.:/usr/bin:/bin and enter the following command:
$ TestString = "$ PATH \" $ PATH"
$ Echo $ TestString
.:/Usr/bin:/bin "$ PATH
$
You can try the result by yourself without adding the second double quotation mark.

Back quote'

The key corresponding to this character is generally located in the upper left corner of the keyboard. Do not confuse it with single quotation marks. The string enclosed by backquotes is interpreted by shell as a command line. During execution, shell program first executes this command line, and replaces the entire anti-quotation mark with its standard output result, which contains two anti-quotation marks. For example:

$ Pwd
/Home/xyz
$ String = "current directory is 'pwd '"
$ Echo $ string
Current directour is/home/xyz
$
When shell program executes the echo command, it first executes the command pwd in 'pwd', replaces the output result/home/xyz with the 'pwd', and finally outputs the entire replaced result.
This function can be used to replace commands. That is, the execution result enclosed by backquotes is assigned to the specified variable. For example:
$ Today = 'date'
$ Echo Today is $ today
Today is Mon Apr 15 16:20:13 CST 1999
$
Backquotes can also be nested. However, you must note that the inner anti-quotation marks must be used as backslashes to escape nested expressions. For example:
$ Abc = 'echo The number of users is 'who | wc-l''
$ Echo $ abc
The number of users is 5
$
Shell special characters can also be used in the command line between backquotes. Shell programming is to get the result of the command in ''. It actually needs to execute the command specified in. Special characters in the command, such as $ ,",? And can contain any legal Shell command, such:

$ Ls
Note readme.txt Notice Unix. dir
$ TestString = "'echo $ home' 'ls [nN] * '"
$ Echo $ TestString
/Home/yxz note Notice
$
In other cases, you can try it yourself.

Annotator

In shell programming, you often need to comment on some body lines to increase the readability of the program. In Shell, the text line starting with the character "#" represents the comment line. In addition, there are some special characters such as <,>, <,>, and | used for input/output redirection and MPs queue &; the Command Execution operators & | and {} representing the Command Group are described in the following sections.

  1. Basic Shell programming syntax in Linux
  2. Linux Shell programming bash Internal commands
  3. Brief Introduction to Fedora Shell programming
  4. Shell programming Overview
  5. Use shell programming to implement DOS-style Linux Command lines

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.