Replace Linux Shell Parameters

Source: Internet
Author: User

Replace Linux Shell Parameters

The $ symbol in Bash is used to replace the parameter name with the value represented by the parameter. For $, braces are optional, that is, $ A and $ {A} represent the same parameter.

$ {} Has the following expressions with colons:
$ {Parameter:-word}
If parameter is null or not set, replace the entire parameter with the expression value of word.
$ {Parameter: = word}
If parameter is null or not set, the entire parameter replaces the expression value with word, and the parameter value is set to word.
$ {Parameter :? Word}
If parameter is null or not set, an error message is printed. Otherwise, the entire parameter replacement expression value is $ parameter.
$ {Parameter: + word}
If parameter is not null or is not set, replace the entire parameter with the expression value of word.
$ {Parameter: offset}
$ {Parameter: offset: length}
The substring of the parameter value.
We can understand the following examples:

$ {}! There are several expressions:
$ {! Prefix *}
$ {! Prefix @}
Print out the parameter names with prefix
$ {! Name [@]}
$ {! Name [*]}
This is for the name array and prints out the subscript of the name array.
We can understand the following examples:

Several expressions with regular expression matching:
$ {Parameter # word}
$ {Parameter # word}
Scan the word from the beginning and filter out the characters matching the regular expression of the word.
# For the shortest match, # For the longest match
$ {Parameter % word}
$ {Parameter % word}
Scan the word from the end and filter out the characters matching the regular expression of the word.
% Is the shortest match, and % is the longest match
We can understand the following examples:

$ {Parameter/pattern/string}
$ {Parameter // pattern/string}
Replace the pattern string corresponding to the parameter value with the string
/Indicates to replace only once
// Replace all
We can understand the following examples:
 

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.