Test whether the variable has been set in linux

Source: Internet
Author: User
In linux, check whether the variable has been set. $ {test:-newvalue }$ {test:-newvalue} is mainly used to test whether the variable test has been defined. if it has been defined, the defined value is printed; if not, the value of newvalue will be printed ,...
In linux, check whether the variable has been set. $ {test:-newvalue} is mainly used to test whether the variable test has been defined. if so
Print the defined value. if there is no value, the newvalue is printed,
Value is assigned to the test variable. Example of www.2cto.com: [root @ redhat ~] # Test = "blue" [root @ redhat ~] # Echo "the sky is $ {test:-gray} today"; the sky is blue today [root @ redhat ~] # Unset test [root @ redhat ~] # Echo "the sky is $ {test:-gray} today"; the sky is gray today www.2cto.com [root @ redhat ~] # Unset test [root @ redhat ~] # Echo "the sky is $ {test:-gray} today"; the sky is gray today [root @ redhat ~] # Echo $ {test} # Here is www.2cto.com 2. $ {test: = newvalue} without the test variable. let's take a look at $ {test: = newvalue} [root @ redhat ~]. # Echo "the sky is $ {test: = gray} today"; the sky is gray today [root @ redhat ~] # Echo $ {test} gray # obviously, $ {test: = newvalue} not only prints the value of newvalue when the test variable is not set,
In addition, newvalue is assigned to the test variable.
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.