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: book/variables_and_subexpressions.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -122,7 +122,7 @@ We can use a variable path to evaluate the variable `$my_value` and get the valu
122
122
testuser
123
123
```
124
124
125
-
Sometimes, we don't really know the contents of a variable. Accessing values as shown above can result to errors if the path used does not exist. To more robustly handle this, we can use the question mark operator to return `null` in case the path does not exist, instead of an error, then we would write custom logic to handle the `null`.
125
+
Sometimes, we don't really know the contents of a variable. Accessing values as shown above can result in errors if the path used does not exist. To more robustly handle this, we can use the question mark operator to return `null` in case the path does not exist, instead of an error, then we would write custom logic to handle the `null`.
126
126
127
127
For example, here, if row `0` does not exist on `name`, then `null` is returned. Without the question mark operator, an error would have been raised instead
128
128
@@ -144,11 +144,11 @@ You can always evaluate a subexpression and use its result by wrapping the expre
144
144
145
145
The parentheses contain a pipeline that will run to completion, and the resulting value will then be used. For example, `(ls)` would run the [`ls`](/commands/docs/ls.md) command and give back the resulting table and `(git branch --show-current)` runs the external git command and returns a string with the name of the current branch. You can also use parentheses to run math expressions like `(2 + 3)`.
146
146
147
-
Subexpressions can also be pipelines and not just single commands. If we wanted to get a list of filenames larger than ten kilobytes, we can use an subexpression to run a pipeline and assign the result to a variable:
147
+
Subexpressions can also be pipelines and not just single commands. If we wanted to get a table of files larger than ten kilobytes, we could use a subexpression to run a pipeline and assign its result to a variable:
148
148
149
149
```
150
-
> let names_of_big_files = (ls | where size > 10kb)
151
-
> $names_of_big_files
150
+
> let big_files = (ls | where size > 10kb)
151
+
> $big_files
152
152
───┬────────────┬──────┬──────────┬──────────────
153
153
# │ name │ type │ size │ modified
154
154
───┼────────────┼──────┼──────────┼──────────────
@@ -175,7 +175,7 @@ It depends on the needs of the code and your particular style which form works b
175
175
176
176
## Short-hand subexpressions (row conditions)
177
177
178
-
Nushell supports accessing columns in a subexpression using a simple short-hand. You may have already used this functionality before. If, for example, we wanted to only see rows from [`ls`](/commands/docs/ls.md) where the entry is at least ten kilobytes we can write:
178
+
Nushell supports accessing columns in a subexpression using a simple short-hand. You may have already used this functionality before. If, for example, we wanted to only see rows from [`ls`](/commands/docs/ls.md) where the entry is at least ten kilobytes we could write:
179
179
180
180
```
181
181
> ls | where size > 10kb
@@ -189,4 +189,4 @@ The `where size > 10kb` is a command with two parts: the command name [`where`](
189
189
> ls | where {|$x| $x.size > 10kb }
190
190
```
191
191
192
-
For short-hand syntax to work, the column name must appear on the left-hand side of the operation (like `size` in `size > 10kb`).
192
+
For the short-hand syntax to work, the column name must appear on the left-hand side of the operation (like `size` in `size > 10kb`).
0 commit comments