syntax:expansion:brace

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
syntax:expansion:brace [2020/06/01 01:06]
fgrose [Brace expansion] provide link to declare page
syntax:expansion:brace [2020/06/28 01:16]
fgrose prefix & suffix are more accurate names for these expansions despite the use of preamble and postscript in the GNU BASH manual.
Line 9: Line 9:
 {<​START>​..<​END>​..<​INCR>​} (Bash 4) {<​START>​..<​END>​..<​INCR>​} (Bash 4)
  
-<PREAMBLE>​{........}+<PREFIX>​{........}
  
-{........}<​POSTSCRIPT>+{........}<​SUFFIX>
  
-<PREAMBLE>​{........}<​POSTSCRIPT>+<PREFIX>​{........}<​SUFFIX>
 </​code>​ </​code>​
  
-Brace expansion is used to generate arbitrary strings. The specified strings are used to generate **all possible combinations** with the optional surrounding ​preambles ​and postscripts.+Brace expansion is used to generate arbitrary strings. The specified strings are used to generate **all possible combinations** with the optional surrounding ​prefixes ​and suffixes.
  
 Usually it's used to generate mass-arguments for a command, that follow a specific naming-scheme. Usually it's used to generate mass-arguments for a command, that follow a specific naming-scheme.
Line 32: Line 32:
 The brace expansion is present in two basic forms, **string lists** and **ranges**. The brace expansion is present in two basic forms, **string lists** and **ranges**.
  
-It can be switched on and off under runtime by using the ''​set''​ builtin and the option ''​-B''​ and ''​+B''​ or the long option ''​braceexpand''​. If brace expansion is enabled, the stringlist in ''​SHELLOPTIONS''​ contains ''​braceexpand''​.+It can be switched on and off under runtime by using the ''​set''​ builtin and the option ''​-B''​ and ''​+B''​ or the long option ''​braceexpand''​. If brace expansion is enabled, the stringlist in ''​SHELLOPTS''​ contains ''​braceexpand''​.
  
 ===== String lists ===== ===== String lists =====
Line 40: Line 40:
 </​code>​ </​code>​
  
-Without the optional ​preamble ​and postscript ​strings, the result is just a space-separated list of the given strings:+Without the optional ​prefix ​and suffix ​strings, the result is just a space-separated list of the given strings:
 <​code>​ <​code>​
 $ echo {I,​want,​my,​money,​back} $ echo {I,​want,​my,​money,​back}
Line 46: Line 46:
 </​code>​ </​code>​
  
-With preamble ​or postscript ​strings, the result is a space-separated list of **all possible combinations** of preamble, ​specified strings ​and postscript:+With prefix ​or suffix ​strings, the result is a space-separated list of **all possible combinations** of prefix or suffix ​specified strings:
 <​code>​ <​code>​
 $ echo _{I,​want,​my,​money,​back} $ echo _{I,​want,​my,​money,​back}
Line 58: Line 58:
 </​code>​ </​code>​
  
-The brace expansion is only performed, if the given string list is really a **list of strings**, i.e. if there'​s ​minimum one "'',''"​ (comma)! Something like ''​{money}''​ doesn'​t expand to something special, it's really only the text "''​{money}''"​.+The brace expansion is only performed, if the given string list is really a **list of strings**, i.e.if there is a minimum ​of one "'',''"​ (comma)! Something like ''​{money}''​ doesn'​t expand to something special, it's really only the text "''​{money}''"​.
  
 ===== Ranges ===== ===== Ranges =====
Line 84: Line 84:
 </​code>​ </​code>​
  
-When you zeropad ​one of the numbers (or both) in a range, then the generated range is zeropadded, too:+When you zero pad one of the numbers (or both) in a range, then the generated range is zero padded, too:
 <​code>​ <​code>​
 $ echo {01..10} $ echo {01..10}
Line 91: Line 91:
 There'​s a chapter of Bash 4 brace expansion changes at [[#​new_in_bash_4.0 | the end of this article]]. There'​s a chapter of Bash 4 brace expansion changes at [[#​new_in_bash_4.0 | the end of this article]].
  
-Similar to the expansion using stringlists,​ you can add preamble ​and postscript ​strings:+Similar to the expansion using stringlists,​ you can add prefix ​and suffix ​strings:
 <​code>​ <​code>​
 $ echo 1.{0..9} $ echo 1.{0..9}
Line 102: Line 102:
 ===== Combining and nesting ===== ===== Combining and nesting =====
  
-When you combine more brace expansions, you effectively use a brace expansion as preamble ​or postscribt ​for another one. Let's generate all possible combinations of uppercase letters and digits:+When you combine more brace expansions, you effectively use a brace expansion as prefix ​or suffix ​for another one. Let's generate all possible combinations of uppercase letters and digits:
 <​code>​ <​code>​
 $ echo {A..Z}{0..9} $ echo {A..Z}{0..9}
  • syntax/expansion/brace.txt
  • Last modified: 2020/06/28 01:16
  • by fgrose