3 ms·
One of my favorite, unexpected features of nushell so far is `$it` the implicit "iteration" variable. It makes sense to have something like this in conjunction
by eigenrick 6y ago
One of my favorite, unexpected features of nushell so far is `$it` the implicit "iteration" variable. It makes sense to have something like this in conjunction with the 'each' command, which makes it very easy to loop over lists or tables.
But $it is still useful in the absence of 'each'.
For instance:
dirname is a useful tool but you can't pipe to it (at least not the GNU version), it expects a string parameter. We can still easily plug it into nushell pipelines though, thanks to $it, which is this case is basically turning stdin into a string.
Since dirname won't let us do
which nu | get path | dirname
we can instead do
which nu | get path | dirname $it
If I wanted to do this in bash, I'd have to go through some annoying (but common) machinations in order to convert stdin into a text string to pass to dirname.
- nitroll 6y agoLike which nu | xargs dirname