syntax:ccmd:case

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:ccmd:case [2013/04/14 12:33]
thebonsai Don't tread version 4 special - it has been around for a long time now
syntax:ccmd:case [2017/02/08 15:04] (current)
fgrose [Description] describe the separation of PATTERNn from surroundings
Line 13: Line 13:
  
 ===== Description ===== ===== Description =====
-The ''​case''​-statement can execute commands based on a [[syntax:​pattern | pattern matching]] decision. The word ''<​WORD>''​ is matched against every pattern ''<​PATTERNn>''​ and on a match, the associated [[syntax:​basicgrammar#​lists | list]] ''<​LISTn>''​ is executed. Every commandlist is terminated by ''<​nowiki>;;</​nowiki>''​, this rule is optional for the very last commandlist (i.e. you can omit the ''<​nowiki>;;</​nowiki>''​ before the ''​esac''​).+The ''​case''​-statement can execute commands based on a [[syntax:​pattern | pattern matching]] decision. The word ''<​WORD>''​ is matched against every pattern ''<​PATTERNn>''​ and on a match, the associated [[syntax:​basicgrammar#​lists | list]] ''<​LISTn>''​ is executed. Every commandlist is terminated by ''<​nowiki>;;</​nowiki>''​. This rule is optional for the very last commandlist (i.e.you can omit the ''<​nowiki>;;</​nowiki>''​ before the ''​esac''​). Every ''<​PATTERNn>''​ is separated from it's associated ''<​LISTn>''​ by a ''​)'',​ and is optionally preceded by a ''​(''​.
  
 Bash 4 introduces two new action terminators. The classic behavior using '';;''​ is to execute only the list associated with the first matching pattern, then break out of the ''​case''​ block. The '';&''​ terminator causes ''​case''​ to also execute the next block without testing its pattern. The '';;&''​ operator is like '';;'',​ except the case statement doesn'​t terminate after executing the associated list - Bash just continues testing the next pattern as though the previous pattern didn't match. Using these terminators,​ a ''​case''​ statement can be configured to test against all patterns, or to share code between blocks, for example. Bash 4 introduces two new action terminators. The classic behavior using '';;''​ is to execute only the list associated with the first matching pattern, then break out of the ''​case''​ block. The '';&''​ terminator causes ''​case''​ to also execute the next block without testing its pattern. The '';;&''​ operator is like '';;'',​ except the case statement doesn'​t terminate after executing the associated list - Bash just continues testing the next pattern as though the previous pattern didn't match. Using these terminators,​ a ''​case''​ statement can be configured to test against all patterns, or to share code between blocks, for example.
  • syntax/ccmd/case.1365942802.txt
  • Last modified: 2013/04/14 12:33
  • by thebonsai