Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
won't try to convince you. But I do :) although it depends on what the script is supposed to do
-
@MrMarco When written well -- yes, clean enough. Verbose - yes, for sure. But it's clean enough.
As for readability - it depends :) -
MrMarco3034y@netikras
I have a theory that Bash is so unintuitive, cryptic and nonsensical that when a developer spends many (hundreds of) hours mastering it they get a sense of accomplishment after achieving even the simplest of task with their script
And then they decide that they like Bash now. Simply because they got it nailed when most people don't.
When in fact the same thing could have been done in 10x less hours with Python and saved the people paying your salary a lot of money.
It's a bit like Stockholm Syndrome -
Problem with python and other higher-level scripting languages, like python, is that they depend on their libraries very much. fIf the library gets an update -- some of your scripts are likely to break. If you port your scripts to another env you need not only python be of the same version but also all the libraries you need for that script.
Unless you are scripting with bare python using only OS API, which I don't think you are :)
As for shell (bash) -- there are no libraries. All you have are bare logic constructs. You can use other preinstalled binaries in the system, but most of the time that is not necessary.
Also you can quickly build a fat oneliner, which is not the case for python, since it's so picky about indentations
I believe these are the reasons why python will never be the default shell language: lack of simplicity and dependency on libraries (effectively breaking portability) and a pricky syntax. -
MrMarco3034y@netikras I actually think Ruby is a better choice than Python but I wanted to use the language people are familiar with as an example.
But no, you wouldn't install any libraries or even use a package manager in this case. I am talking about replacing one bare language with another (one with a simpler and more intuitive syntax) -
Voxera115854yBash is first and foremost a command line language.
Multi line constructs are the exception
Its core purpose is different from python and python would need a lot of extra features to support all the piping and similar that are very useful in cmd.
And nothing prevents you from using python in scripts, just add a first line indicating the interpreter to use and you are good, without having to burden python with a full cmd mode.
Yes I know you have the interactive mode, but there is still things missing for fast clobbered together commands.
Splitting something into functions the python way is not practical for day to day operations where most commands are not reused. -
@Voxera
>Splitting something into functions the python way is not practical for day to day operations where most commands are not reused.
I'd argue with that. Building shell-based tools with functions does make the script a lot cleaner and easier to maintain. Also prevents you from using terrible practices, like global variables, reusing variables multiple times, etc.
Functions also help to separate namespaces where some pieces of logic are sourced from other files (scripts)
Both of the above save you a lot of debugging time :) -
@MrMarco well IDK about python being intuitive.. Spawning other processes and seeing/piping their output seems A LOT simpler in bash :D
How do you do "ls -ltrh | awk -F: '/^20191.*access$/ {print $NF}'" with Py? or Ruby? :) -
The thing is (and ive done many experiments on this as I dislike bash myself) but for simple lower level tasks, bash is fast, really fast.
I've tried comparing tasks like file searching and such before with scripts I wrote in python and php, but bash didn't just win, it freaking destroyed the competition.
Almost like regex, its ability makes it just enough to be worth it -
Voxera115854y@netikras your still stuck in scripting mode.
95+ % of all bash I use is either single line operations or one of constructs I never reuse.
Once in a while I realize I reuse a construct and create a macro/alias or a script to do it.
But for most parts its one liners.
And I have been using bash regularly for 20+ years and programming fir 40 years -
Voxera115854y@stonestorm exactly, bash is very good and quite simple for its main purpose, and when your needs are different, just use another language for the script.
Common bash tools like awk is actually a scripting language in it self ;), and I have even used php for scripting one since we found a library that perfectly matched our requirements that was php only :)
And looking at a more modern command line option created more recently you have power shell.
And despite being more modern with real object passing support its syntax, in my opinion, borrows more from bash than from other programming languages.
And thats because its still a cmd first language, not a programming or scripting language.
Your example with regex was good :)
Regex os probably one of the least readable languages you can find, but replacing it requires so much extra work that its not feasible for the cases it is designed for.
But when using it for the wrong task, its horrible;) -
Voxera115854y@netikras you missed the last part “which are not reused”
Creating separate scripts or functions for one of operations is not time efficient and debugging is most often not required for one offs ;) -
@Voxera umm.. awk is not a bash tool :) It's another binary in the system that can be launched by bash or any other shell.
As for PowerShell and Objects -- ksh93 has that nailed since long, LONG time ago ;) which is also a shell/scripting language, very similar to bash
I guess it depends on how we use shell. I for use use bash very extensively, building sophisticated tools (thousands of lines) with it along with the simple ones. From your comments I see that you use shell for simpler tasks, simple oneliners, scripts. Frankly I find very handy to use functions ;) -
Voxera115854y@MrMarco your still stuck thinking that most bash is used for scripting, its not.
Bash is, was and continue to be a command line shell first and fore most and scripting was added afterwards before most modern scripting languages was available.
And as a command line tool, bash is very easy to use in most cases while retaining the option for more complex operations if you need to.
And any really advanced stuff you build in whatever language you prefer and then use as a command.
Python is better at many things but cannot replace bash as a command line without major redesigns.
And once you start doing those redesigns you are likely to break the nice syntax of python and end up with something even worse ;) -
Voxera115854y@netikras I agree, in my day to day use I use bash primarily to do simple maintenance of linux machines.
For anything more complex I usually turn to better scripting languages, but I have done some odd things in bash that it was not designed for ;)
It is possible, but it is not really practical :P
Awk was just an example of what many might see as “just another command” in bash but which as you said is its own program.
And thats another beauty of bash, its easy to extend by building “your own commands” since one major feature is easy interaction with other executables, something that is not quite as easy in most normal scripting or programming languages (disclaimer, rest apis has done a good job of replicating this ) -
MrMarco3034y@Voxera I'm glad you mentioned this because I think we are kind of on the same page on this point.
I do realise that it's not meant for scripting and is intended to be a CLI language.
But the issue is that it *does* end up getting used for scripts, even though it's not intended to. Maybe the companies I've worked for have just been neverminded - but I have seen a lot of bash scripts. People end up doing that because it can run on the next machine easily, out of the box.
And this is my whole point - Bash keeps getting used for it's unintended purpose, which is (medium to) complex scripting. And it's not very good at it. Understandably, because of it's age, but still.
Times have changed and it would be nice to have a lightning fast, clean, readable scripting language as the default shell language.
As for the issues we might encounter on redesign - You might be right. Honestly I haven't tried. But I think we can do better than bash. -
Voxera115854y@MrMarco the problem is that command line and scripting has different goals and combining them in one will most likely be hard.
Might be better to allow easy use of cmd syntax embedded in the script, a bit like linq in c# or similar.
But you end up with a new scripting language which takes time to get accepted.
Another solution would be (this might already exist) a set of libraries for python for easy integration with a shell, like easy execution of cmd statements with piping into and out of, easy access to environment variables and such.
Then you can use the best tool for every situation mixing them as you need.
But as you said, bash is a standard available out if the box, python needs installation which n many cases is a deal breaker.
Also as you mentioned, people and systems that started before modern scripting are unlikely to change, its just to much work compared to just educating the new people. -
Bash is a special-purpose language, wich also happens to be turing complete. If used for executing applications in a fixed order, it is actually less verbose than Python.
If used to write actual applications, it is hell. -
Even if the idea behind Bash is beautiful, truth is the syntax kinda sucks... Why don't you try to make your own shell? Also, you might like FISH (the shell).
-
MrMarco3034y@aggelalex As you might be able to tell, it has crossed my mind to make a better shell LOL.
But it's a lot of work so I'd need a couple of people who are equally invested as I am ;)
Also, making it the new standard would be an immense task.. Unless it's backwards compatible 🧐 -
@MrMarco I'm super into this stuff, especially languages and Linux technologies. I might as well try to do this sometime. Backwards compatibility is not an issue I believe, after all you can just run bash scripts in Bash and select a different extension for your own shell's scripts. All you need to do is take the things Bash does well and redesign them.
-
MrMarco3034y@aggelalex If you do this, let me know. I’d be keen to contribute or even just brainstorm
-
@Voxera
> For anything more complex I usually turn to better scripting languages, but I have done some odd things in bash that it was not designed for ;)
>
> It is possible, but it is not really practical :P
I see you there! :)
https://gitlab.com/netikras/bthread ## because FUCK PARALLEL and other dependencies!!!
https://gitlab.com/netikras/bhttp ## Fiest your eyes on the readability at example.bash!
https://gitlab.com/netikras/bjson ## a bit broken. Sorry for that..
https://gitlab.com/netikras/... ## because why not
With bthread lots of my tools got a second life :)
So yeah, I would not dare to maintain any of my utils if I were't using functions :) Even if they are not being reused anywhere. They help me to SRP and KISS -
Can we call the new shell pysh? People will pysh themselves.
Edit: also this: http://pysh.sourceforge.net/ -
Gophyr19224yBefore going off and trying to write a completely new shell from scratch, I'd recommend taking a look at something like Oil Shell (https://oilshell.org).
On another note, there's one feature of shell scripting that I haven't seen mentioned yet (unless I missed it, which is possible) that I find extremely useful: everything is a string. Given how much stuff I need to interact with (paths, file names, configs, logs) is all plain text strings, having the default type in a language being the string is incredibly useful. -
I recently found this through TLDRNews:
https://github.com/hauntsaninja/pyp
Haven't tried it out but looks promising and the author also mentions comparable tools and shells in the readme -
holloway594ySince I don't work with it very much, but also find the need to write bash from time to time, I rather dislike it. It's not like a lot of modern languages, which for the most part are interchangeable or at least easier to understand in relation to each other.
One thing that always buggers me up is writing "bash" vs writing posix-compliant shell code. There are odd caveats here and the community seems to care 50% of the time. -
Bash is really useful when automating stuff that uses files, you need more code in a language like Python to do that
-
Voxera115854y@netikras ery cleaver solution with the fd piping. I could have used this about 20 years ago when I designed my first high performance mail sender.
I used bash and some lose parts of qmail but used standard piping so the results had to go into separate scripts that posted it into the db again.
But it ran 20 parallel instances of the qmail sender application :)
With a library like this I could have made it so much more elegant.
But I rewrote it in C to solve some problems with performance. -
@netikras regarding no libraries in the shell:
Most commands on the shell are executions of rando binaries you happen to have lying around in your PATH. Most of the time, those are standard tools you can reasonably expect to have on any given linux box. However, a lot of the time, they're not. Dealing with json, for example, has competing non standard solutions.
Anyway my point is bash scripts often have dependencies just like python scripts -
@M3m35terJ05h That is a fair point. But ptobability of already finding those utils on a LINUX/UNIX setup already preinstalled is way higher than finding any of the python libraries :)
-
@netikras but that’s sort of a double edge sword... because the python standard library has pretty much everything bash can offer + a few more things (like multiprocessing and abstraction functions for stuff like argument parsing). The only thing you don’t have, is out of the box simple API for running commands...
On the other hand, because bash has no other library support, then you cant really do more slightly complex things (like html parsing without regex hell or building simple rest APIs).
Plus, honestly, python , js, ruby, really any other scripting language is sooo much more verbose and simple...
Like you can’t tell me that doing [[ -z “$VAR” ]] is more verbose then len(var) == 0 or doing var.length == 0 or really anything else -.-
And that’s just 1 example of how cryptic bash is. Try parsing an env variable that’s supposed to be a comma separated value, in any scripting language it’d be a simple var.split(“,”).map(x=>x.trim()) or something similar to this. In bash... shit man, bring out the IFS=‘, ‘ read -r -a <<< “$var”
Related Rants
Bash is a ridiculous language.
Imagine if a the default shell language was quick and easy (like Python) how much quicker you'd be able to whip up a script - or even debug it.
And to all the bash lovers, no I don’t care about the history of the stupid language and don't try and convince me you whip up a quick script in 2 minutes.
rant
bash