summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2020-09-14 23:14:09 +0430
committerAndreas Kling <kling@serenityos.org>2020-09-15 20:36:59 +0200
commit3a8109d1e022123a66f45745c78002a9f08c3366 (patch)
treed79a5c425e66171962c2c54a5660b2f8a61f0408
parent4f223793c0da55e2931e94236bc04faa1f70928f (diff)
downloadserenity-3a8109d1e022123a66f45745c78002a9f08c3366.zip
Shell: Add some sections on the manpage about `match'
-rw-r--r--Base/usr/share/man/man5/Shell.md24
1 files changed, 24 insertions, 0 deletions
diff --git a/Base/usr/share/man/man5/Shell.md b/Base/usr/share/man/man5/Shell.md
index 5c299ce74e..590288d1f8 100644
--- a/Base/usr/share/man/man5/Shell.md
+++ b/Base/usr/share/man/man5/Shell.md
@@ -60,6 +60,8 @@ The following tokens:
* `in` as a syntactic element of a `for` expression
* `if` in command name position, or after the `else` keyword
* `else` after a partial `if` expression
+* `match` in command name position
+* `as` as part of a `match` expression
##### Special characters
Any of the following:
@@ -251,6 +253,28 @@ $ fn 1 2 3 4
# 1 2 3 ( 1 2 3 4 )
```
+##### Match Expressions
+The pattern matching construct `match` shall choose from a sequence of patterns, and execute the corresponding action in a new frame.
+The choice is done by matching the result of the _matched expression_ (after expansion) against the _patterns_ (expanded down to either globs or literals).
+Multiple _patterns_ can be attributed to a single given action by delimiting them with a pipe ('|') symbol.
+
+The expanded _matched expression_ can optionally be given a name using the `as name` clause after the _matched expression_, with which it may be accessible in the action clauses.
+
+######
+```sh
+# Match the result of running 'make_some_value' (which is a list when captured by $(...))
+match "$(make_some_value)" as value {
+ (hello*) { echo "Hi!" }
+ (say\ *) { echo "No, I will not $value" }
+}
+
+# Match the result of running 'make_some_value', cast to a string.
+match "$(make_some_value)" {
+ hello* { echo "Hi!" }
+ say\ * { echo "No, I will not!" }
+}
+```
+
## Formal Grammar
### Shell Grammar