mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:27:44 +00:00
Shell: Allow parts of globs to be named in match expressions
This patchset allows a match expression to have a list of names for its glob parts, which are assigned to the matched values in the body of the match. For example, ```sh stuff=foobarblahblah/target_{1..30} for $stuff { match $it { */* as (dir sub) { echo "doing things with $sub in $dir" make -C $dir $sub # or whatever... } } } ``` With this, match expressions are now significantly more powerful!
This commit is contained in:
parent
0801b1fada
commit
1a4ac3531f
6 changed files with 115 additions and 10 deletions
|
@ -51,3 +51,33 @@ match "$(echo)" {
|
|||
};
|
||||
|
||||
test "$result" = yes || echo invalid result $result for string subst match && exit 1
|
||||
|
||||
match (foo bar) {
|
||||
(f? *) as (x y) {
|
||||
result=fail
|
||||
}
|
||||
(f* b*) as (x y) {
|
||||
if [ "$x" = oo -a "$y" = ar ] {
|
||||
result=yes
|
||||
} else {
|
||||
result=fail
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test "$result" = yes || echo invalid result $result for subst match with name && exit 1
|
||||
|
||||
match (foo bar baz) {
|
||||
(f? * *z) as (x y z) {
|
||||
result=fail
|
||||
}
|
||||
(f* b* *z) as (x y z) {
|
||||
if [ "$x" = oo -a "$y" = ar -a "$z" = ba ] {
|
||||
result=yes
|
||||
} else {
|
||||
result=fail
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test "$result" = yes || echo invalid result $result for subst match with name 2 && exit 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue