8

Why people uses Python for OS scripting? What’s the point in forcing me to download a proper interpreter to run a script when the same result can be achieved with a more portable and cleaner Bash/PowerShell script?!?!

Comments
  • 16
    Because using python tends to lead into more portable and cleaner scripts.
  • 2
    I ask myself that all the time. Why can't i just do it with JS. 🤣
  • 2
    @electrineer it depends, for example os.system is still OS dependent
  • 6
    @DEVil666 You can still write cross platform scripts without rewriting it all in either bash or power shell.
  • 8
    Because as soon as it gets more complex, you just don't want that as bash script.
  • 4
    even harder, why do we use Python when we already have the power of the camel inside of every nix variant and portable scripts for strawberry perl on windows?

    * strawberry perl is not portable
    * dodges show
    * exits the room
  • 16
    Powershell / bash = cleaner?

    Compared to what, a cluster fuck of spaghetti?

    🤷‍♂️
  • 12
    @AleCx04 Yeah, just like why do we have a toilet when we already have a balcony? :-)
  • 3
    Yeah why not use Visual Basic? It comes with literally every OS!
  • 4
    Same people that hand out jar files without the runtime, like I'm expected to install that shit somewhere global.
  • 2
    Possibly because said scrips need to be cross-platform or needed to do things that are tricky to achieve in PowerShell/Batch in Windows or Bash in other OSs.
    And a number of OSs/distros these days comes with Python pre-installed so it's not as much as issue than if say it was Node.js, Go, Perl or any other languages that can accomplish such tasks.
  • 1
    Some OS come with already installed interpreters for languages like python or ruby or you can install them within seconds with a single command line call.
  • 2
    Python has nowadays Poetry and VEnvs.

    And Bash is limited.

    It's good for simple stuff, but you'll have to be clever and disciplined.

    Even in larger upstream projects, eg. Dockerfiles from NGINX, there are some low quality shitty Bash scripts. It's rare for me to read _good_ Bash scripts....

    E.g. an JSON parser in Bash based on JQ is a bad idea - much easier and far less brain fart in Python.

    IO streams. Memory handling. Large text / log parsing and forwarding to e.g. an HTTP Endpoint.

    All things that you could do in Bash, but in Python it's far easier.

    What makes Bash scripting even harder is that it's dependent on how well behaved the programs are that the Bash script uses...

    E.g. grepping output cause the program just fails with return code 1 for a warning... Or even worse: Return code is 0. Always.

    Had all these kinds of fun. It's shit.

    A true Python Binding or library is easier to handle than the execution of a binary.

    I could go on - but the essence is: Choose the enemy wisely.

    Bash, as you'll have to run commands to achieve functionality, can be quite a burden.

    Python has libraries, poetry and VENVs and a lot of stuff comes for free.
  • 2
    And Bash isn't portable... At least not if other commands are used.

    Nope...

    Absolutely not.

    As e.g. the commands differ from OS to OS, version and so on...

    And you cannot build static binaries that run exactly the same on all OSes, portability is non existent.

    Even Bash in the same version on e.g. Windows vs Linux can be quite different.

    It's not impossible if it is a true pure Bash script, but the layers you'll have to add are quite troublesome as Bash is limited.
  • 3
    @Berkmann18 actually you should leave Go out of it as it's compiled. So you would have a binary for each platform but no need to download/install Go itself. Just like if you would make it in C/C++
  • 2
    because world is build in python
  • 2
    The same reason, why they don't write them in C:
    Python code is way better maintainable.

    That may not matter for your own scripts. But distributions and OSS projects are almost always horribly understaffed and therefore just can't afford to maintain lots of barely legible code.

    Decades ago, they had to trade off speed and legibility. But that times are over now and therefore the more maintainable language wins even if it is an order of magnitude slower.
  • 1
    @AleCx04 I aprov camel
  • 1
    @iiii right??? i feel that the camel power is severely underappreciated in this place :(
  • 0
    But but. Tab loops ftw? 😂😂

    Sorry I like python, but that was the worst mistake ever. Try programming python in a browser.. like for Spark with Jupyter
  • 1
    @C0D4

    I don't know,

    ```
    for f in dir/*.txt
    do
    # something
    done
    ```

    Feels way cleaner to me than the Python alternative.

    People just don't take the time to learn bash properly
  • 1
    @Fast-Nop well you've convinced me.

    I'll probably save money on not having to flush my toilet too
  • 1
    @IntrusionCM Python doesn't behave the same on Windows and Linux either, at least not when doing the sort of OS-related stuff you'd normally use Bash for.
  • 1
    @YADU half true in my opinion.

    E.g. pathlib in Python deals with a lot of the stuff you would have to write manually.

    Without readlink from the coreutils e.g. you cannot even write path independent bash scripts, as you cannot resolve symbolic links / paths.

    I like Bash. Maybe we got off on the wrong foot, as all kinds of red flags alarm when someone mentions bash and portable in a sentence...

    If possible, yes. bash could do.

    If necessary, Python is a viable alternative.

    But bash without coreutils? Really not useable.
Add Comment