What happens if the expansion of a parameter is unset?
Otherwise, the value of parameter is substituted. $ {parameter:=word}. If parameter is unset or null, the expansion of word is assigned to parameter . The value of parameter is then substituted. Positional parameters and special parameters may not be assigned to in this way.
When do you use parameter expansion in Bash?
Parameter expansion can be used to modify, expand or replace the value of the parameter. The optional braces are used with the variable when using variable parameter expansion, such as ‘echo $ {myvar}’. How parameter expansion can be used in bash for various purposes are shown in this tutorial.
What are the different types of parameter expansion?
Parameter expansion can be categorized by three groups. These are conditional parameter expansion, substring parameter expansion, and substitute parameter expansion. The uses of these parameter expansions are explained with examples in the next part of this tutorial. These types of parameter expansions are used to check the variable is set or unset
What does indirect expansion do to a parameter?
This is known as indirect expansion . The value is subject to tilde expansion, parameter expansion, command substitution, and arithmetic expansion. If parameter is a nameref, this expands to the name of the variable referenced by parameter instead of performing the complete indirect expansion.
What does it mean to expand a parameter in Bash?
Bash uses the value formed by expanding the rest of parameter as the new parameter; this is then expanded and that value is used in the rest of the expansion, rather than the expansion of the original parameter. This is known as indirect expansion.
When to use case modification in parameter expansion?
Case modification can be used to create the proper capitalization for names or titles. Just assign it to an array: For array expansion, the case modification applies to every expanded element, no matter if you expand an individual index or mass-expand the whole array using @ or * subscripts.