Substitution of shell variables, command substitution, escape character

Source: Internet
Author: User
Tags delete key

Substitution of 1,shell variables

Variables can be replaced by a specific value depending on whether the variable is empty or deleted

${var} variable Original value

$ (Var:-word) If the variable is empty or has been deleted then return to Word, but do not change the value of Var

Name= "Xiaoming"

echo "Xiaoming ' s Age is ${age:-12}"

Ech "age = ${age}"

>>>>>>>>

Xiaoming ' s age is 12

Age =

>>>>>>>

$ (Var:=word) If the variable is empty or has been deleted then return to Word and change the value of Var

Name= "Xiaoming"

age=11

echo "Xiaoming ' s Age is ${age:+12}"

Ech "age = ${age}"

>>>>>>>>

Xiaoming ' s age is 12

Age = 12

>>>>>>

$ (Var:?word) If the variable is empty or has been deleted then return to Word, then send the message to the standard error output

Name= "Xiaoming"

echo "Xiaoming ' s Age is ${age:-12}"

Ech "age = ${age}"

>>>>>>>>

./hello.sh: Line 8:age:12

>>>>>>>

$ (Var:+word) If VAR is defined, then return to word, but do not change the value of Var

Example

Name= "Xiaoming"

age=11

echo "Xiaoming ' s Age is ${age:=12}"

Ech "age = ${age}"

>>>>>>>>

Xiaoming ' s age is 12

Age = 11

>>>>>>>

2, command substitution means that the shell can perform a command save and then output it in the appropriate place

Lll= ' ls ' note here is the anti-quote, not single quote
Echo ${lll}

3, escape character

\ \ counter Slash

\a Alarm Ringing

\b Backspace (delete key)

\f Page Change

\ nthe line break

\ r Enter

\ t Horizontal tab

\w Vertical Tab


Substitution of shell variables, 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.