diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2021-03-13 03:10:18 +0330 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-03-22 13:15:08 +0100 |
commit | 3b8fa5a75387d1b9a609dca1d911bebfacdf7060 (patch) | |
tree | 557fe261c7c4a0af3a0da026d87fa63e89a55697 /Userland/Shell/Formatter.h | |
parent | ddcef0452aad489a51f4cf3d67e7517f3e573e7c (diff) | |
download | serenity-3b8fa5a75387d1b9a609dca1d911bebfacdf7060.zip |
Shell: Add support for indexing into variables
Now a variable may have an optional slice (only _one_ slice), which can
also use negative indices to index from the end.
This works on both lists and strings.
The contents of the slice have the same semantics as brace expansions.
For example:
```sh
$ x=(1 2 3 4 5 6)
$ echo $x[1..3] # select indices 1, 2, 3
2 3 4
$ echo $x[3,4,1,0] # select indices 3, 4, 1, 0 (in that order)
4 5 2 1
$ x="Well Hello Friends!"
$ echo $x[5..9]
Hello
```
Diffstat (limited to 'Userland/Shell/Formatter.h')
-rw-r--r-- | Userland/Shell/Formatter.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/Userland/Shell/Formatter.h b/Userland/Shell/Formatter.h index d7bff364e0..76aab3d912 100644 --- a/Userland/Shell/Formatter.h +++ b/Userland/Shell/Formatter.h @@ -90,6 +90,7 @@ private: virtual void visit(const AST::ReadWriteRedirection*) override; virtual void visit(const AST::Sequence*) override; virtual void visit(const AST::Subshell*) override; + virtual void visit(const AST::Slice*) override; virtual void visit(const AST::SimpleVariable*) override; virtual void visit(const AST::SpecialVariable*) override; virtual void visit(const AST::Juxtaposition*) override; |