3 ms·
While these are good examples of some of the fragile parts of bash, I think switching shells is the wrong approach in this case. If you find yourself dealing w
by tyingq 5y ago
While these are good examples of some of the fragile parts of bash, I think switching shells is the wrong approach in this case. If you find yourself dealing with binary data, floating point math, complex quoting, and so on...you probably shouldn't be scripting with a shell. Use Python, Perl, Ruby, or something else more suited to the task.
- nerdponx 5y agoI don't agree with this. Shell syntax is uniquely flexible and powerful when it comes to composing pipelines. It often is precisely the right tool for the job. Floating point math and "complex" quoting come up pretty often in a wide range of relatively basic tasks. Even something as simple as computing a percentage literally cannot be done in Bash without forking out to an external program. Sure, you could use a tool that does that one thing and does it well, or you could just have it in your shell and not worry about it. The whole point about quoting is that it's hard to get right even when you're trying. It gets even harder when you are dealing with things like arrays and command substitution. You could switch to another programming language... or you could just use a shell that does these things right from the outset!
- vips7L 5y agoOr use powershell and have all the power of C# at your finger tips and shell scripting at the same time!
- tyingq 5y agoOff topic, but I do like powershell. The lack of a reasonable way to have it NOT pop a console window is regrettable though. What is provided still pops a console window, just for a shorter amount of time.
- GSGBen 5y agoMassive pain point. Here's a workaround though: https://github.com/stax76/run-hidden https://github.com/stax76/run-hidden
- kimbernator 5y agoPowershell does have some really cool shit as far as scripting languages go, but it's just so damn verbose.
- vips7L 5y agoIt comes with a lot of aliases and does fuzzy matching on arguments. For example: gci -r The -r will fuzzy match to -Recurse. It’s a change going to an OO shell from bash but I run it on windows and WSL. The windows integration is really good too.
- BeetleB 5y agoOr use xonsh, which has all the power of Python and shell scripting at the same time!
- zeppelin101 5y agoXonsh is damn impressive and I loved playing around with it. But it is really slow.
- lukeschlather 5y agoI used to say this, but Powershell has really proven to me that we need a shell that is also a good scripting language. Powershell has its faults, but it's as good as any scripting language, especially when time is a factor. And it does this without sacrificing its utility as a shell. I haven't spent time with elvish but I think it's moving more in the right direction. Zsh and friends are better than bash but they are still too sh-like and a lot of those conventions are just always going to be problems.
- arp242 5y agoThere are all sorts of cases where you have a simple script that's perfectly fine, but you want to just add two fractions, or store a bit of binary data in a variable. I think those are reasonable expectations, and I don't think that "rewrite it to {Python,Ruby,...}!" is really a great solution (partly because for some simple tasks writing it in Python, Ruby, etc. is a lot more work). "If you want it, then this is not the right tool" doesn't strike me as a very strong argument for missing basic features such as this. For advanced complex features? Maybe. But not this. I also don't think shell scripting is quite as bad as people make it out to be, or rather, one of the reasons people hate it is because they use bash or POSIX sh, and yeah, that gets problematic fast. The point of the article was to demonstrate that actually, you can solve a decent chunk of the problems and get something much less problematic without a lot of effort, while still retaining the key advantages of shell scripting. However, even if we exclude all of scripting: you can't write your ~/.{bash,zsh}rc in Python, and it's useful for interactive usage as well.