Testing and content substitution for shell variables

Source: Internet
Author: User

Reference "Bird's private cuisine--linux Basic Study (third edition)".

In "bird Brother's private cuisine--linux Basic Study (third edition)" in the 11th chapter, bird Brother about the variables of the test and the content of the replacement, the bird brother finally illustrated in the example of variable substitution '-', ' = ', '? ' Usage of three special symbols.

After reading these routines, give me the biggest feeling is Var=${str-newvar} or Var=${str=newvar} or Var=${str? Newvar} variable substitution is the only three-mesh operator in C language? is similar in usage:

max= (x>y)? (x:y). Here we analyze the following:

Var=${str-newvar}: If Str does not exist, then Var=newvar; Select the latter

If STR exists, then VAR=${STR}; Select the former

Similarly, "=" can also be interpreted as:

Var=${str=newvar}: If Str does not exist, then Var=newvar; Select the latter but because it is equal to the number, so str=newvar;

If STR exists, then VAR=${STR}; Select the former str to keep the original content


For "? "is interpreted as"

Var=${str? No this variable}: If Str does not exist, the output error message: no this variable; Select the latter

If STR exists, then VAR=${STR}; Select the former str to keep the original content




Testing and content substitution for shell variables

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.