Linux Gvim Shell Replacement: variable substitution, command substitution, escape character

Source: Internet
Author: User
Tags delete key echo command

Replace: If the expression contains special characters, the shell will replace it. For example, using a variable in double quotes is a substitution. The escape character is also a replacement

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

The #-e indicates that the escape character is replaced with no output as follows #

echo "Value of A is ${a} \ n"

Escape character Substitution

The following escape characters are available for Echo

1. \ \ Backslash
2. \a Alarm, Bell?
3. \b Backspace (delete key)?
4. \f The page, move the current position to the beginning of the next page
5. \ n line break
6. \ r Enter
7. \ t One indent
8. \v Vertical tab?

Examples are as follows:

1 Echo " Value of A is ${a} \ \ " 2 Echo " Value of A is ${a} \ t ${a} "

You can suppress escaping by using the-e option of the Echo command, which is not escaped by default, or by using the-n option to prevent insertion of line breaks


Command substitution

The shell executes the command first, saves the output temporarily, and outputs it in the appropriate place.
The grammar ' command ' is the one under ESC.

Examples are as follows:

1Date= 'Date`2 Echo "Date is ${date}"3 4Users= 'W.H.O.|WC-l '5 Echo "logged in USR is $USERS"6 7Up= 'Date;Uptime`8 Echo "Uptime is ${up}"

Variable substitution

Can be based on the state of the variable (empty?) Defined? ) to change its value.
You can use the variable substitution form as follows
1. The original value of the ${var} variable
2. ${var:-word} If the variable var is empty or has been unset, return to Word without changing its value
3. ${var:=word} If the variable var is empty or has been unset, return to Word and set its value to Word
4. ${var:?message} If the variable var is empty or has been unset, then send the message 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
6. ${var:+word} If the variable var is defined, then return to word, but do not change its value

Examples are as follows:

1 Echo${var:-"Variable is not set"}2 Echo "1-value of Var is ${var}"3 4 unset var5 Echo${var:+"The is default value"}6 Echo "3-value of Var is ${var}"7 8 Echo${var:="Variable is not set"}9 Echo "2-value of Var is ${var}"Ten  OneVar="Chenmo" A Echo${var:?"Print This message"} #把ChenMo输出终端 # - Echo "4-value of Var is ${var}" -  theVar="Matto" - Echo${var:+"This is the default Valus"} - Echo "Value of Var is ${var}"









Linux Gvim Shell Replacement: variable substitution, command substitution, escape character

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.