About variable settings in the shell

Source: Internet
Author: User

Defining variables

A=

Assigning values to variables

A=5


' Number equals $ ()

[Email protected] ~]# hostname

Localhost.localdomain

[Email protected] ~]# a= ' hostname '

[Email protected] ~]# echo $a

Localhost.localdomain



${-} to determine whether the variable is set, if not set, use-the next assignment value is null value

[Email protected] ~]# c=

[[email protected] ~]# Ab=${path-/usr/sbin}

[Email protected] ~]# echo $ab

/usr/sbin

[Email protected] ~]# echo $path


[Email protected] ~]#

If path has no value, it is assigned to AB using the/usr/sbin value.

If path has a value, assign the value of path to AB


${:-} Determines whether the variable is not set, or is set to a null value, and if it is not set or is empty, the following content is used to assign the value


So generally in the judgment we can completely abandon ${-}, directly using ${:-string} to achieve









About variable settings in the shell

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.