Replacement in the shell

Source: Internet
Author: User
Tags delete key

If there are some special characters in the shell, you need to replace them, you can do command substitution, variable substitution, escape substitution

1. Substitution of escape characters

The shell contains the following transfer characters

\a Bell alarm \ \ Backslash

\b Backspace (delete key)

\f (FF), moves the current position to the beginning of the next page

\ nthe line break

\ r Enter

\ t Horizontal tab

\v Vertical Tab

The above transfer characters can be used in echo, by using-E to complete the replacement of the escape character, the person will be output as-is, or through-e prohibit the transfer, through-n can prohibit inserting line break

2. Command replacement

The following declaration assigns the command date to date, noting that the command here must be extended with an inverted parenthesis instead of a single quote

1 [email protected] ~/shell2 $ date= 'DATE'34 [email Protected] ~/shell5echo  $DATE6:  -

3. Variable substitution

Variable substitution is based on whether it is empty, whether it is defined, and the value of the variable can be changed

Alternate form of a variable:

Form Description
${var} The variable's original value
${var:-word} If the variable var is empty or has been deleted (unset), it returns word, but does not change the value of Var
${var:=word} If the variable var is empty or has been deleted (unset), return to Word and set the value of Var to Word
${var:?message} If the variable var is empty or has been deleted (unset), the message messages are sent to the standard error output, which can be used to detect whether Var can be assigned to a normal value. If this substitution appears in the shell script, the script will stop running
${var:+word} If the variable var is defined, then return to word, but do not change the value of Var

PostScript: None

Replacement in the shell

Related Article

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.