Beehaw
  • Communities
  • Create Post
  • search
    Search
  • Login
  • Sign Up
alexcoder04 ( alexcoder04@programming.dev )  to Programmer Humor@programming.devEnglish · 3 years ago

python < shell (for scripts)

programming.dev

message-square
39
link
fedilink
383

python < shell (for scripts)

programming.dev

alexcoder04 ( alexcoder04@programming.dev )  to Programmer Humor@programming.devEnglish · 3 years ago
message-square
39
link
fedilink
  • Kogasa ( kogasa@programming.dev ) 
    link
    fedilink
    arrow-up
    10
    ·
    3 years ago

    I can’t think of a single reason to use bash over Python. Anything you can do in bash can be done in pure Python. Unless you’re working in some embedded environment it’s a non-issue to install a Python interpreter (you certainly already have one). I would only use sh/bash for packages I’m distributing to avoid the external dependency, and then only if it’s a relatively simple script.

    • bort ( bort@lemmy.sdf.org ) 
      link
      fedilink
      arrow-up
      13
      ·
      3 years ago

      I know whatever environment I run my shell script in has sh, I can’t rely on (the right version of) python being there.

      • Kogasa ( kogasa@programming.dev ) 
        link
        fedilink
        arrow-up
        1
        ·
        3 years ago

        Why not?

    • Reborn2966 ( Reborn2966@feddit.it ) BannedBanned
      link
      fedilink
      arrow-up
      9
      ·
      3 years ago

      i would not run a python script with root.

      • Kogasa ( kogasa@programming.dev ) 
        link
        fedilink
        arrow-up
        5
        ·
        3 years ago

        That’s fair.

    • alexcoder04 ( alexcoder04@programming.dev ) OP
      link
      fedilink
      arrow-up
      8
      ·
      3 years ago

      Bash is much better for doing file operations and piping the output across multiple commands

      • corm ( corm@beehaw.org ) 
        link
        fedilink
        arrow-up
        1
        ·
        3 years ago

        Better than subprocess.getoutput?

    • CoderKat ( CoderKat@lemm.ee ) 
      link
      fedilink
      English
      arrow-up
      6
      ·
      3 years ago

      Python is superior for string anything (parsing, searching, manipulating). But Bash is much simpler for running existing CLI tools. Plus you should already be using Bash as a simple terminal language already, so wrapping what you’re used to into a simple script flows naturally.

      Eg, if I have some admin tool for updating a user thingamajig, a common scripting need is just running that tool for every user in a file (or the output of another command). The string manipulation that often requires is annoying in bash, but running the commands is easier than Python.

      • Kogasa ( kogasa@programming.dev ) 
        link
        fedilink
        arrow-up
        4
        ·
        3 years ago

        If what you’re doing is essentially a few shell commands, then you may as well put it into a script. If you’re talking about how “elegant” your shell scripts are and comparing them to Python, you’re probably wrong and should be using Python.

    • MonkderZweite ( MonkderZweite@feddit.ch ) 
      link
      fedilink
      arrow-up
      6
      ·
      3 years ago

      Why is always about bash? POSIX shell scripts run everywhere.

      • IRQBreaker ( IRQBreaker@lemmy.kozow.com ) 
        link
        fedilink
        arrow-up
        2
        ·
        3 years ago

        Granted, it’s a kind of niche use case but in the embedded world there’s usually size constraints which prevents a full blown bash installation.

        However, things are better now than 20 years ago. Flash is cheap.

Programmer Humor@programming.dev

programmer_humor@programming.dev

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !programmer_humor@programming.dev

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics
    • If the mod doesn’t find it funny, you’re banned. Ha-ha!.. For real: do not use the community for “statements”. There are other places for such content. Keep it chill and funny.
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 318 users / day
  • 1.57K users / week
  • 5.09K users / month
  • 8.2K users / 6 months
  • 464 local subscribers
  • 34K subscribers
  • 1.63K Posts
  • 26.9K Comments
  • Modlog
  • mods:
  • Feyter ( Feyter@programming.dev ) 
  • adr1an ( anzo@programming.dev ) 
  • BurningTurtle ( BurningTurtle@programming.dev ) 
  • Pierre-Yves Lapersonne ( pylapp@programming.dev ) 
  • BE: 0.19.21
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code