Linux Shell parameter substitution

Source: Internet
Author: User
Tags ord

Linux Shell parameter substitution

2013-06-03 10:01 by Xuan Blade, 1816 Read, 0 reviews, Favorites, compilation

Bash in theCharacterNo.OfForUseIsParameterNumberForChange,WillParameterNumberNameForChangeForParameterNumberTheGenerationTableOf value < Span style= "font-family:stixgeneral, ' Arial Unicode MS ', serif; font-size:90%; Font-style:normal; Font-weight:normal; " > to on

, the curly braces are optional, i.e.A and

{A} represents the same parameter.

${} There are several expressions with colons: ${parameter:-word}

If parameter is null or not set, the entire parameter substitution expression value is word

${parameter:=word}

If parameter is null or not set, the entire parameter substitution expression value is word, and the parameter parameter value is set to Word

${parameter:?word}

If parameter is null or not set, an error message is printed. Otherwise, the entire parameter substitution expression value is $parameter

${parameter:+word}

If parameter is not NULL or not set, the entire parameter substitution expression value is word

${parameter:offset}${parameter:offset:length}

A substring of the value of the parameter.

Here are some examples to understand:

${} band! There are several expressions: ${!prefix*}${[email protected]}

Prints the name of the parameter with the prefix prefix

${!name[@]}${!name[*]}

This is for the name array, which prints out what subscript the name array has

Here are some examples to understand:

${} Several expressions with regular matches: ${parameter#word}${parameter# #word}

Scan Word from the beginning to filter out characters that match the word's regular expression

#为最短匹配, # #为最长匹配

${parameter%word}${parameter%%word}

Scan Word from the end to filter out characters that match the word regular expression

% is the shortest match and the percent is the longest match

Here are some examples to understand:

${parameter/pattern/string}${parameter//pattern/string}

Replace the pattern string of the parameter corresponding value with a string string

/means replace only once

means replace All

Here are some examples to understand:

Linux Shell parameter substitution

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.