Skip to content

Commit ffaf308

Browse files
authored
Update moving_around.md (#1258)
1 parent 8b3e224 commit ffaf308

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

book/moving_around.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ Globbing syntax in these commands not only supports `*`, but also matching [sing
3131
Escaping `*`, `?`, `[]` works by quoting them with single quotes or double quotes. To show the contents of a directory named `[slug]`, use `ls "[slug]"` or `ls '[slug]'`.
3232
Note that backtick quote doesn't escape glob, for example: <code>cp `test dir/*`</code> will copy all files inside `test dir` to current direcroty.
3333

34+
If you pass a variable to a command that support globbing like this: `let f = "a[bc]d.txt"; rm $f`. It won't expand the glob pattern, only a file named `a[bc]d.txt` will be removed. Normally it's what you want, but if you want to expand the glob pattern, there are 3 ways to achieve it:
35+
36+
1. using spread operator along with `glob` command: `let f = "a[bc]d.txt"; rm ...(glob $f)`. This way is recommended because it's expressed most explicitly, but it doesn't work with `ls` and `du` command, for the case, you can
37+
2. using `into glob` command: `let f = "a[bc]d.txt"; ls ($f | into glob)`. It's useful for `ls` and `du` commands.
38+
3. annotate variable with `glob` type: `let f: glob = "a[bc]d.txt"; rm $f`. It's simple to write, but doesn't work with external command yet.
39+
3440
## Changing the current directory
3541

3642
@[code](@snippets/moving_around/cd_example.sh)

0 commit comments

Comments
 (0)