Shell script: Replace

Source: Internet
Author: User

Escape character

#!/bin/Basha=tenecho"Value of A is $a \ n"

Replace the escape character with the-e representation, which is not escaped by default

Command substitution

The syntax for command substitution, note is the inverse quotation mark, not the single quotation mark, this key is below the ESC key.

' Command '

You can save the results of a command execution in a variable and use it when needed

#!/bin/bashdate=' Date 'echo' Now '${date}'

Variable substitution

Variable substitution can change its value depending on the state of the variable (whether it is empty, whether it is defined, etc.)

Variable substitution forms that you can use:

Here is an example of variable substitution

#!/bin/BashEcho${var:-"Variable is not set"}Echo "1-value of Var is ${var}"Echo${var:="Variable is not set"}Echo "2-value of Var is ${var}"unset varEcho${var:+"The is default value"}Echo "3-value of Var is $var"var="Prefix"Echo${var:+"The is default value"}Echo "4-value of Var is $var"Echo${var:?"Print This message"}Echo "5-value of Var is ${var}"

Run results

Shell script: Replace

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.