News for hackers. Stuff that matters.
Re:Zx 3.0 by cfeliped on Monday August 16, 2021 @06:10AM (#28196517)
In my first job I gave a try at using Python for scripts.

It was a terrible idea, as I now had 3 problems instead of 1:

1 - Writing scripts, plus:

2 - Installing Python in every host that needed to run those scripts

3 - Maintaining Python and the necessary dependencies up to date in each host / container.

(2) and (3) are trivial when done just once in your own computer, but end up being a huge time sink for larger heterogeneous environments with (possibly) network and security barriers. Moreover, if you are using containers, installing Python will make images unecessarily large.

Granted, I'm not a JS person, but I imagine one will have the same issues.

Even though bash has its shortcomings, I really appreciate how low maintenance it is as long as you keep scripts small and sane.

Re:Zx 3.0 by qalmakka on Monday August 16, 2021 @06:23AM (#28196577)
That's why Perl is my go-to choice for glue scripts. It's almost always installed by default, it has stayed consistent for decades without any breaking changes, its regex support is by far the best around, and its almost as good as the shell at gluing commands together.
Re:Zx 3.0 by nyanpasu64 on Monday August 16, 2021 @07:01AM (#28196771)
I'm less likely to have Perl installed than Python on Windows, where I sometimes want my scripts to run as well.
Re:Zx 3.0 by qalmakka on Monday August 16, 2021 @10:32AM (#28198564)
It's also unlikely you have Python installed on Windows though, and there's a non-insignificant change that's an old or random version (probably even Python 2). You can't rely on anything on Windows, so you're definitely going to also install a runtime from Chocolatey or similar.
Re:Zx 3.0 by thatwasunusual on Monday August 16, 2021 @09:52AM (#28198064)
> That's why Perl is my go-to choice for glue scripts. It's almost always installed by default

My first thought was related to this as well: Perl is _always_ installed, and based on Python's popularity (compared to Perl, at least), I'd assume that Python also was installed by default?

That's an honest question, btw: I use Perl quite a lot, Python not so much (at all). :)

Re:Zx 3.0 by cfeliped on Monday August 16, 2021 @10:09AM (#28198294)
Assuming Python or Perl are installed by default in any server is an invite to a world of pain. At least that's my anecdotal experience.
Re:Zx 3.0 by qalmakka on Monday August 16, 2021 @10:34AM (#28198595)
I've seen instances of some Unix systems not having Perl installed, but that's very rare. Basically everything directly or indirectly depends on Perl, so you really have to run your scripts on a minimal install of RHEL of FreeBSD with 0 ports in order to get into such a situation.
Re:Zx 3.0 by mst on Monday August 16, 2021 @01:02PM (#28200302)
And for that situation you can always break out http://p3rl.org/App::staticperl.

Plus of course if you want to use (pure perl) cpan dependencies I wrote http://p3rl.org/App::FatPacker and http://p3rl.org/Object::Remote to make that easier.

Re:Zx 3.0 by thatwasunusual on Monday August 16, 2021 @10:50PM (#28205637)
> And for that situation you can always break out http://p3rl.org/App::staticperl.

Why do you link to p3rl.org? And, more importantly, why do you link to something that doesn't exist?

Re:Zx 3.0 by cfeliped on Monday August 16, 2021 @01:29PM (#28200620)
Many container base images won't have perl by default (e.g: alpine).

For servers it's less common, but enterprise systems never cease to amuse me.

Re:Zx 3.0 by qalmakka on Thursday August 19, 2021 @05:27AM (#28231877)
Most container base images are often so barebone you can't really count on them containing anything. For instance, on an Alpine image you can't count on bash.
Re:Zx 3.0 by thatwasunusual on Monday August 16, 2021 @10:47PM (#28205606)
Why?
Re:Zx 3.0 by andrewl-hn on Monday August 16, 2021 @06:26AM (#28196595)
JS is marginally better than Python for this, because tools for runtime and package version management are better for Node than for Python (proper lockfiles, local package folders, npm bundled with Node for installation, etc.).

Still, zx isn't as nice as Ruby, which has backticks for calling shell as part of the language. So, you don't have to have a separate package installed, just the ruby runtine.

But Perl is even better! Just like Ruby, it comes with backtick shell execution build-in, but unlike Ruby Perl is ubiquitous and is pretty strict about backward compatibility. So, your scripts will just run on all machines you have, no matter what distro you use and how old the machine is (within reason).

Re:Zx 3.0 by ptx on Monday August 16, 2021 @12:30PM (#28199912)
Zx seems[1] to take advantage of the way template literals work in JS to do proper shell escaping of the parameters to prevent command injection. Is that handled by the Ruby and Perl backtick syntax as well?

[1] https://github.com/google/zx/blob/3.0.0/test.mjs#L30-L33

Re:Zx 3.0 by gravypod on Monday August 16, 2021 @09:11AM (#28197606)
Luckily today you can side step many of these issues. You can compile a copy of python + modules + pex into a single file with some open source tooling and get a flat file you just need to copy to your hosts.
Re:Zx 3.0 by sumtechguy on Monday August 16, 2021 @10:46AM (#28198738)
Bash just sort happened to be the lowest common denominator in most unix style environments. Because it just sorta ended up being the default. Unix ended up being this different thing where each distro seems to be kind of unique. Then on top of that they are very easy to customize. So while one distro you can assume a particular python level the next disto python is totally optional. Mix in containers and docker images and you have a new level of 'what may or may not be there'. Ah but you may say 'oh just use tech XYZ' that may or may not have the exact same issue as using python in its place. So either 'deal with it' and install what is needed and keep it up to date. Or 'play the LCD game' you use only the bare min and hope you can build something useful enough in bash when another lang may be more appropriate.
Re:Zx 3.0 by hulitu on Monday August 16, 2021 @12:02PM (#28199591)
I thought that was sh (i.e. bourne shell). As far as i remember bash is not the default shell on a lot of unices.
Re:Zx 3.0 by cfeliped on Monday August 16, 2021 @01:31PM (#28200632)
My understanding is that sh is a specification, not an implementation.

Most images will either have bash or ash installed. ash, being lightweight, is the choice of alpine and related distros.

Re:Zx 3.0 by asveikau on Monday August 16, 2021 @03:32PM (#28201887)
This is a bit of a Linux specific view of the universe. Yes posix has a standard for how sh should work. But there were specific implementations of sh, and you would get those on commercial Unix or *BSD.

Later shells came in and filled some gaps. OpenBSD still has ksh by default. Linux distros had bash as their /bin/sh.

Re:Zx 3.0 by cfeliped on Monday August 16, 2021 @05:25PM (#28203190)
I didn't know that. Thank you for the explanation!