4 ms·
I've just skimmed around it as someone who repeatedly need that kind of book to achieve little things in bash. I understand bash is the basis of so many things
by wiz21c 7y ago
I've just skimmed around it as someone who repeatedly need that kind of book to achieve little things in bash.
I understand bash is the basis of so many things, that its importance is just enormous.
But at the same time, I'm appalled by its syntax, idioms, etc. It's barely readable for the casual reader that I am. I wonder why nobody tries to provide a meaningful alternative. I've seen some (in python for example) but I'm kind of surprised nobody puts more money in such an effort.
For example, the "trim string" function described at the beginning of the book is horrible (although probably very clever). Why not simply provide a built in function ? That would make code so much cleaner...
I ask the question honestly, it's not a rant :-)
- orev 7y agoShells are made for people to interact with, not for programming. They happen to also be useful for programming, so many things have been added on over time to support that. Shell scripting is also the least painful way to call many external programs and glue them together into something useful. Calling external programs from “real” programming languages is far more painful. If you need a real programming language, as you mentioned, use something designed for that.
- pjc50 7y agoGenerally if you're trying to do something that feels like a "program" in shell script, rather than loosely gluing existing tools together, the threshold for moving it into Perl or Python should be low. Even things like trying to get the quoting right for lists of files some of which may have spaces in their names is fiddly enough to drive people to writing a "proper" program. (or was this comment intended for https://news.ycombinator.com/item?id=21013150 https://news.ycombinator.com/item?id=21013150 )
- robohoe 7y agoThe moment I have to use arrays in bash, I open up a python interpreter. Syntax makes far more sense than in bash.
- kjeetgill 7y agoI used to drop into python for ad-hoc work as soon as I needed even for/if or any arithmetic. Now that I actually manage to remember how to use for-loops when I need them and I picked up awk,I haven't needed to since. For a maintainable script pythons great of course.
- master-litty 7y agoIts simplicity is an important part of the offering. Bash is perfect when you need predictable executions. When you use Bash, you benefit from an entire ecosystem that also uses it. That same ecosystem is not motivated to drastically change the shell, and therefore it remains stable and predictable. Bash typically isn't like Python or JavaScript, where certain features are introduced at a particular version and you have to constantly check for them, or not use them outright, or maintain which binary you have installed at all times. One Bash binary typically contains the same feature set as another binary. Bash isn't the friendliest thing to work with syntactically, but it's friendlier than the alternatives in maintability and reliability. Despite all this, on the flip side, there still are a lot of people invested in alternatives, and some have gained plenty of traction. zsh is a great example.
- laumars 7y agoI don't disagree with your points but I think your following comment is a little misleading: > Bash typically isn't like Python or JavaScript, where certain features are introduced at a particular version and you have to constantly check for them, or not use them outright, or maintain which binary you have installed at all times. One Bash binary typically contains the same feature set as another binary. While you're right about shell builtins (a lot of which are defined by POSIX anyway), to do anything useful in POSIX shells requires forking out to sed, awk, grep, as well as many other coreutils and CLI tools. Thus you then need to not only confirm whether those tools are also installed but sometimes also which version or even implementation they are (eg GNU extends on POSIX in quite a number of ways from supported features through to how you order and group flags. Sometimes it can be a little jarring jumping from Linux to OSX if you're used to GNU). That said, I do working in shells. For "getting shit done" very little even comes close to shells in terms of productivity. However shells are generally optimised to the "write many read once" end of development rather than "write once read many". As an aside, I suspect GP meant to post this comment on https://news.ycombinator.com/item?id=21013150 https://news.ycombinator.com/item?id=21013150 (Pure Bash Bible - also on the front page) rather than here?
- master-litty 7y ago
- nickjj 7y agoI guess it's like anything programming related. Things don't make sense until they make sense. Bash's syntax is a bit rough at times and I often find myself having to Google things even though I know what I want to do at a conceptual level. But the real magic isn't just Bash alone. It's combining it with Unix tools to pipe together programs to solve problems. I guess at the end of the day no one has tried to fix it because they don't see it as a problem. Despite the syntax weirdness at times it's a pretty concise language which meshes well with writing ad-hoc things on the command line. IMO Bash is often the best tool to use for a ton of different problems. Sometimes it's good for a final result and sometimes it's good to flesh out a prototype because you can hack something together so fast.
- toyg 7y agoThe real advantage it has is simply that it’s there, always. It enjoyed a network effect a long time ago and is now so entrenched that challengers have a mountain to climb - entire generations of professionals know how to get stuff done with it and expect it to be there from the start, so any system that goes with an alternative is at an immediate disadvantage. A few OSes are trying to push what are effectively incremental updates (like ksh on OpenBSD), but it’s a daring proposition. I like OpenBSD but still the first thing I do is switch back to bash, because there are so many other things on the todo list that dealing with an unfamiliar shell is both incredibly low priority and the first thing I’m forced to do - a perfect “demotivational” combo. I fear it would take a massive coordinated switch, systemd-like, where an entire ecosystem moves to an alternative, to actually see any change in this area.
- nickjj 7y ago> The real advantage it has is simply that it’s there, always. Yes, this is a huge deal in a good way. It's also why standalone zero dependency Python scripts are so successful since most systems have Python installed by default. Although after reading your first sentence, I got excited. I thought you were going to write about how it's always there in the sense that if you're working in the terminal, Bash and friends are always right there at your finger tips. There's no context switch to get something done, which is super empowering for hacking together things to solve a problem. It just feels like the whole terminal environment in general was made to let tinkerers create the best possible system / workflows for them personally.
- chacha2 7y agoStrangely no one's pointed this out yet but you appear to have posted this comment in the wrong thread. This seems to be the post you're replying to. https://news.ycombinator.com/item?id=21013150 https://news.ycombinator.com/item?id=21013150
- james_s_tayler 7y agoIt's not syntax. It's programs. [ Is a program. Bash blew my mind when I found that out. What a clever idea. I know what you mean though. I always had to look up things every time. Lately I just committed a bunch of it to memory as it's useful enough and I'm pretty fond of it.
- Kaiyou 7y agoBash is similar to vim. Pretty weird at first glance, but once you get the idea, stuff just makes sense and the limited knowledge you acquire can be used in different contexts. I think bash is magical in the things it allows you to do with minimal effort.
- farisjarrah 7y agoI would highly suggest checking out Powershell. It works great on windows and linux, its object oriented, and it has all sorts of "networked" capabilities built into it to. For example, say you want to get the disk space on your own computer: Get-WmiObject Win32_LogicalDisk If you want to do that on a remote machine you just add this to the end of the command -ComputerName remotecomputer: Get-WmiObject Win32_LogicalDisk -ComputerName remotecomputer And then you can just use the returned object to iterate over it: $disk = Get-WmiObject Win32_LogicalDisk -ComputerName remotecomputer -Filter "DeviceID='C:'" | Foreach-Object {$_.Size,$_.FreeSpace}