Test and content replacement of shell variables, replacement of shell Variables

Source: Internet
Author: User

Test and content replacement of shell variables, replacement of shell Variables

Reference: laruence's private house dish-Linux BASICS (Third edition).

In Chapter 11th of the Linux BASICS (Third edition, the final example illustrates '-', '=', and ','? 'Usage of three special symbols.

After reading these routines, I feel like var =$ {str-newvar}, var =$ {str = newvar}, or var =$ {str? Is the replacement of the newvar} variable the only three-object operator in the C language? The usage is similar:

Max = (x> y )? (X: y ). The analysis is as follows:

Var =$ {str-newvar}: If str does not exist, var = newvar; // select the latter

If str exists, var =$ {str}; // select the former

Similarly, "=" can be explained as follows:

Var =$ {str = newvar}: If str does not exist, var = newvar; // select the latter, but str = newvar because it is an equal sign;

If str exists, var =$ {str}; // select the former str to keep the original content.


For "?" Is interpreted as"

Var =$ {str? None of the variables}: If str does not exist, an error is returned: none of the variables; // select the latter

If str exists, var =$ {str}; // select the former str to keep the original content.




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.