5 ms·
So, '>' isn't for redirection anymore. How does one do that? open foo.txt | append "world"| save --raw foo.txt Oh.
by akira2501 4y ago
So, '>' isn't for redirection anymore. How does one do that?
open foo.txt | append "world"| save --raw foo.txt
Oh.
- pxc 4y agoThis reminds me of how Fish handles process substitution without requiring a special syntax. I love it! It may seem a bit odd or even cumbersome to experienced shell programmers, but in my experience with Fish, this kind of thing helps a lot with ease of learning.
- andrepd 4y agoIt is much much better to have things be actual commands (which have a uniform syntax, and are `--help`able) rather than obscure sigils like $(#!@$). Fish is amazing!
- pxc 4y agoMany of these next-gen shells like Nushell are clearly (and sometimes explicitly) inspired equally by Fish and by PowerShell, and it shows. It's a brilliant combination!
- amelius 4y agoI think the problem with this approach is that it breaks down at some point, and then your only option is to rewrite the entire thing in a real scripting language. I.e., there is no graceful scaling path.
- pxc 4y agoI suppose I'm more optimistic. From my point of view, structures pipelines and some of the goodies that come with it (like better error handling), can make a shell language into a perfectly capable scripting language. I think the big weakness for these new shells is in the small sizes of their library ecosystems. But PowerShell shows what a language of this kind can do with a sizeable ecosystem and some OS integration.
- stingraycharles 4y agoIsn’t this the problem with older shells as well? Eg you have to use e.g. awk or sed to deal with more complicated text processing. My understanding that the biggest difference between powershell (and nushell) and the older bash-like shells is that they deal with structured, object-like data rather than text. How would things be any different when “things break down” vs an older shell?
- jrumbut 4y agoOne of the nice things about bash is that it interacts very nicely with Perl and Ruby. I wonder how these other shells work with the backticks and such in Perl/Ruby. Theoretically there is room for very cool interoperability but I wonder how it goes in practice and if any nice tools and patterns are being developed.
- phist_mcgee 4y agoSince this is nushell and perl and ruby are now starting to be considered 'old, is that so much of a problem?
- jrumbut 4y agoIt's a path to scaling. You can basically dump a shell script (I assume including nushell) into your .pl/.rb file with a little punctuation and then slowly refactor it to a language that can handle greater complexity.
- ilyt 4y agoShould be doing that anyway, bash is terrible for actual programs.
- coldtea 4y agoAs opposed to what? Regular shells which break down even quicker? And there's no hard constraint that would require this to "break down at some point". A well designed shell could also be a "real scripting language", all-in-one. But the horrible CP/M and POSIX legacy of shell design doesn't help with that.
- ofchnofc 4y ago[dead]
- inciampati 4y agoFish is amazing. And. It was missing critical features like subprocesses for so long (10 years?) that I had to keep passing it by. No subprocesses!
- pxc 4y agoI'm not sure what you mean here. The term 'subprocess' doesn't appear in the fish or bash manuals afaict. (Most web search results for the word 'subprocess' paired with the names of various shells are about Python APIs for shelling out to stuff.) The term does appear in an O'Reilly book about the Korn shell, which identifies command substitution (`$()`) as a form of subprocess. But I think Fish has had command substitution from the start. The same goes for job control, which is the only other thing I could think of that you might mean by the term 'subprocess'. There are some old job control bugs, job control behaviors that used to not be POSIX compliant, and one outstanding bug having to do with IO redirection in fish functions that seem like they could be sort of relevant here. But there's nothing I can think of that I could interpret as 'lacking subprocesses'. I only spent a few minutes looking into this, though. I'm curious to know if you can still recall more specifics, so many years later! Maybe there's something from before I started using fish that I've missed here. But fish is only 18 years old, going by the date of its first release, and I've been using it as a daily driver for ~13 years, and it has had everything I might call 'subprocesses' for that entire duration.
- jntrnr 4y agoOr: open foo.txt out> bar.txt
- codetrotter 4y agoHistorically we would discourage shell users from cat somefile.txt | whatever and instead tell them to use either whatever < somefile.txt or, if the command accepts input file names as arguments then use those like whatever somefile.txt or whatever -i somefile.txt etc But perhaps in fish, “useless use of cat” is not so useless and would be recommended? (I mean aside from the fact that they seem to recommend their “open” command, and so they probably prefer their own “open” over “cat”.)
- mtlmtlmtlmtl 4y agoFor some reason I never liked to do it the "right way". First of all it doesn't seem to actually matter. But most of all the cat way just aligns with my mental model more. Data flows left to right, if you catch my drift. It also makes it easier to add arguments to the end if re-running it.
- tomsmeding 4y agoWhile I get your point... > It also makes it easier to add arguments to the end if re-running it. I'd like to point out that a redirection doesn't have to be the last thing in a command. E.g. the common 'echo >&2 "some message"' works fine.
- Arnavion 4y ago>But most of all the cat way just aligns with my mental model more. Data flows left to right, if you catch my drift. Using `<` doesn't change that model. You can write `< somefile.txt whatever`. I always write my commandlines as `<in_file cmd1 | cmd2 | cmd3 >out_file` (Though annoyingly this doesn't work for feeding input to while loops. `< <(echo a; echo b; echo c;) while read -r foo; do echo "$foo"; done` is invalid syntax; it needs to be `while read -r foo; do echo "$foo"; done < <(echo a; echo b; echo c;)`)
- cerved 4y agodoesn't it work if you put it after the while but before the read?
- e12e 4y agoHm. Why not re-use "tee"? https://www.man7.org/linux/man-pages/man1/tee.1.html https://www.man7.org/linux/man-pages/man1/tee.1.html
- pxc 4y ago`save` seems to be a general serialization command, which lets you save Nu objects in formats like JSON, YAML, and others. The `--raw` option seems like a convenience for enabling that tee-like usage without relying on external programs, but the driving use case is serializing structured data rather than unstructured text or byte streams.
- e12e 4y agoAh, I failed to realize that nushell deals with rich data. I think this might hit the sweetspot for me, for dealing with json - I never could get a feel for "jq" like I have with sed/awk, and don't much enjoy powershell. I don't think I need a new shell (bash is fine - and I would probably move to fish for a new shell if I were to change) - but I certainly need a sane way to wrangle json (hello docker inspect!) and yaml (hello kubectl/k8s and github actions!).
- pxc 4y agoFWIW, I've made basically the same call for now: Fish has been my daily driver for some time, but I have a lot of interest in Nushell and some real affection for Elvish, and I think I'd like to eventually make the switch to one of these newfangled shells with the structured pipelines one day. The great thing about shell languages is that you get to practice the scripting language with your everyday interactive usage, which is one of the main reasons I'd eventually like to switch, even if I see that perhaps the most exciting use cases are wrangling JSON and YAML in scripts.