19
MrMarco
9d

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.

Comments
  • 10
    won't try to convince you. But I do :) although it depends on what the script is supposed to do
  • 2
    @netikras Do you find it to be a clean and readable language?
  • 4
    @MrMarco When written well -- yes, clean enough. Verbose - yes, for sure. But it's clean enough.

    As for readability - it depends :)
  • 6
    @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
  • 15
    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.
  • 7
    @MrMarco aaahhh, you must be confusing bash with perl then :D
  • 1
    @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)
  • 18
    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.
  • 2
    @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 :)
  • 3
    Well 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.
  • 2
    @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? :)
  • 4
    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
  • 4
    @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
  • 1
    @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;)
  • 1
    @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 ;)
  • 1
    @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 ;)
  • 1
    @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 ;)
  • 0
    @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 )
  • 0
    @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.
  • 0
    @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.
  • 0
    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.
  • 0
    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).
  • 0
    @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 🧐
  • 0
    @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.
  • 0
    @aggelalex If you do this, let me know. I’d be keen to contribute or even just brainstorm
  • 1
    @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
  • 0
    Can we call the new shell pysh? People will pysh themselves.

    Edit: also this: http://pysh.sourceforge.net/
  • 0
    Before 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.
  • 0
    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
  • 0
    Since 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.
  • 1
    Bash is trash

    Hahahahahahaha
  • 0
    Bash is really useful when automating stuff that uses files, you need more code in a language like Python to do that
  • 1
    @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.
  • 1
    @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
  • 0
    Complaining about a bodged language designed to bodge other things.
  • 0
    @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 :)
Add Comment