After I learned how subshells can be executed within nushell I was confident that I could handle that part. But few minutes ago I run into an error I didn’t really understand:
❯ rpm -qf (which dwebp) error: Type Error ┌─ shell:24:16 │ 24 │ rpm -qf (which dwebp) │ ^^^^^ Expected string, found row
I thought the parameter was provided somehow in the wrong way, and put it into quotes:
"dwebp". But it didn’t help. I tested around more with sub-shells, some of them worked while others didn’t. The error message was misleading for me, letting me think that there is a difference in how the argument is interpreted:
❯ rpm -qi (echo rpm) Name : rpm Version : 22.214.171.124 Release : 1.fc34 [...] ❯ echo (which dwebp) ───┬───────┬────────────────┬───────── # │ arg │ path │ builtin ───┼───────┼────────────────┼───────── 0 │ dwebp │ /usr/bin/dwebp │ false ───┴───────┴────────────────┴─────────
It took me a while until I understood what I was looking at – and to make the error message make sense: the builtin nushell command
which can give back multiple results, thus returning a table. The builting nushell command
echo returns a string!
Thus the right way to execute my query is to get the content of the cell of the table I am looking at via
❯ rpm -qf (which dwebp|get path|nth 0) libwebp-tools-1.2.1-1.fc34.x86_64
nth 0 is not strictly necessary here since there is only one item in the table anyway. But it might help as a reference for future examples.
You don’t have to use pipe, btw., there is an even shorter way available:
❯ rpm -qf (which dwebp|nth 0).path libwebp-tools-1.2.1-1.fc34.x86_64
One thought on “[Short Tip] Accessing tabular nushell output for non-nushell commands”