by eigenrick · 6y ago · 0 comments
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.