Remix.run Logo
mdaniel 3 days ago

This trope comes up every time bash is mentioned, without fail. Unless your team enjoys reading this, then no, a general purpose programming language is not a good replacement for what is effectively a "subprocess orchestration language":

  from subprocess import run, PIPE
  home = os.getenv("HOME")
  try:
    os.chdir(f"{home}/dev")
  except FileNotFoundError:
    sys.exit(1)
  out = run(("git ls-remote https://github.com/%(repo)s refs/tags/%(tag)s"
            % {"repo": shlex.quote("myorg/myrepo"), "tag": shlex.quote("v1.2.3+deadbeef")}).split(" "),
            stdout=PIPE, stderr=PIPE)
The line noise is outrageous as compared to a language built for changing directories and running commands

That's not even getting into the pty portion, where the progress of the output isn't visible until the end of it, which is terrible DX

Too 2 days ago | parent | next [-]

Nice rube goldberg machine. Apart from imports, that is equivalent to

    repo = "myorg/myrepo"
    tag = "v1.2.3+deadbeef"
    out = check_output(["git", "ls-remote", f"https://github.com/{repo}", f"refs/tags/{tag}"], cwd=os.path.expanduser("~/dev"), stderr=PIPE)
Converting exceptions to exits is an anti-pattern that hides the source of the error, f-strings has been a thing for 10 years and argument quoting happens automatically. Progress of output isn't visible in bash either when you capture output with $(), unless you "tee", which opens up another can of "pipefail"-worms.
aborsy 2 days ago | parent | prev | next [-]

This falls under the case “unless the bash script is simple “.

If you consider more complex tasks, bash quickly gets unwieldy, and the situation is reversed.

Pythons has a lot of advantages, including full flexibility, error handling etc.

BeetleB 2 days ago | parent | prev [-]

In xonsh[0], that would be:

    cd $HOME/media
    git ls-remote ...
(Not sure about the equivalent of shlex.quote, but in the worst case, you can just use "from shlex import quote as q" or something).

So yes, there are good alternatives to bash - even Python based.

[0] https://xon.sh/