Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
won't try to convince you. But I do :) although it depends on what the script is supposed to do
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.
@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)
Bash 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.
>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 :)
Haxk20444419dWell written bash is clean and very readable.
Yes i hated it at the start too. But the more you have to use it the more readable the code you write is.
Now i kinda love it as you can whip out script easily in few minutes if you know what to do.
And if you dont then dont take it as bad thing. Take it as challenge and learn new methods that you can do in the language.
Also what you are saying could be applied to C too.
Sure its hard language and for some people unreadable. Learn it and write it well and trust me its easier then fucking python.
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
@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
@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;)
@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 ;)
@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 ;)
@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 )
@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.
@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.
Oktokolo4139dBash 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).
@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.
> 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
Gophyr20899dBefore 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.
holloway589dSince 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 trash
Bash is really useful when automating stuff that uses files, you need more code in a language like Python to do that
@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
Complaining about a bodged language designed to bodge other things.