You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: blog/2022-03-22-nushell_0_60.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -272,7 +272,7 @@ In this release, we're also moving to keeping the current directory in the envir
272
272
This allows you to more easily loop over subdirectories without having to do the bookkeeping of remembering to change back to the previous directory:
273
273
274
274
```
275
-
> ls | where type == dir | each { |it| cd $it.name; ls | length }
275
+
> ls | where type == dir | each { |row| cd $row.name; ls | length }
276
276
```
277
277
278
278
That said, it takes a little getting used to. It does mean that changing a directory in a traditional custom command won't work, as the `PWD` environment variable will reset after the call completes. To help with this, we're also introducing `def-env`, a way to work inside the caller's environment and not lose any environment changes made by the custom command:
@@ -685,18 +685,18 @@ The new engine has a fun trick up it's sleeve: you can effortlessly convert your
685
685
For example, if we had a script that opened files that fit a certain pattern and counted their number of lines:
686
686
687
687
```
688
-
ls **/*.rs | each { |it|
689
-
let num_lines = (open $it.name | lines | length)
690
-
{name: $it.name, loc: $num_lines}
688
+
ls **/*.rs | each { |row|
689
+
let num_lines = (open $row.name | lines | length)
690
+
{name: $row.name, loc: $num_lines}
691
691
}
692
692
```
693
693
694
694
We can turn this into a script that runs in parallel by changing the `each` to `par-each`:
Copy file name to clipboardExpand all lines: blog/2024-02-06-nushell_0_90_0.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -113,7 +113,7 @@ So if you have the following files: `aac.txt`, `abc.txt`, `a[ab]c.txt`, then:
113
113
But if you save a file name in a variable, e.g: `let f = "a[ab]c.txt"`, then `ls $f` matches `aac.txt`, `abc.txt`.
114
114
To escape the glob pattern to match a file named `a[bc]c.txt`, `str escape-glob` comes to play: `ls ($f | str escape-glob)`.
115
115
116
-
The new `str escape-glob` command ([#11663](https://github.com/nushell/nushell/pull/11664)) is useful when you want to prevent globs from expanding, for example when using a closure: `ls | str escape-glob name | each {|it| ls $it.name }`, so you won't get error occasionally.
116
+
The new `str escape-glob` command ([#11663](https://github.com/nushell/nushell/pull/11664)) is useful when you want to prevent globs from expanding, for example when using a closure: `ls | str escape-glob name | each {|row| ls $row.name }`, so you won't get error occasionally.
0 commit comments