News for hackers. Stuff that matters.
Re:Bash-oneliner: A collection of handy Bash one-liners and ... by gnubison on Tuesday May 03, 2022 @05:26PM (#31253803)
Even better, use a real text editor like ed or ex. (Nowadays ex is more portable because many distros — against POSIX — omit all 55 kilobytes of GNU ed. Of course, smaller systems might not have ex/vi.)

Basic usage looks like this:

    printf '%s\n' '" some commands...' 'wq' | ex -s file
Or:

    ex -s file <<'EOF'
    " some commands...
    wq
    EOF
By the way, these commands are the ones that you use in your vimrc or after a colon in vim — at least, the POSIX subset of that — so any ex commands you learn translate naturally to your normal editor.
Re:Bash-oneliner: A collection of handy Bash one-liners and ... by mdaniel on Tuesday May 03, 2022 @05:34PM (#31253888)
That's an interesting trick, I'll bear it in mind.

That said, the "lottery factor" is often a bigger contributor to the things that land in codebases than "optimality". Plus, I've actually seen somewhere that perl is the most common binary across every system, and it's likely a larger population who know perl than ed would be my guess

Re:Bash-oneliner: A collection of handy Bash one-liners and ... by bradknowles on Wednesday May 04, 2022 @01:23AM (#31257026)
With Perl, you can't just say "Perl", you have to be specific to which version of Perl.
Re:Bash-oneliner: A collection of handy Bash one-liners and ... by jwilk on Wednesday May 04, 2022 @02:06AM (#31257222)
What do you mean?
Re:Bash-oneliner: A collection of handy Bash one-liners and ... by bradknowles on Wednesday May 04, 2022 @02:11AM (#31257250)
How many major versions of Perl do you know about?

What is the distribution of these different versions of Perl across various OSes and OS versions?

Hint: Lots of backward-incompatible changes tend to get made around different major versions. Having Perl 4 is not like having Perl 5 which is not like Perl 6.

Re:Bash-oneliner: A collection of handy Bash one-liners and ... by jwilk on Wednesday May 04, 2022 @02:32AM (#31257387)
I still don't know what your point is.

Are there any contemporary distros that have the "perl" exectuable that is not Perl 5?

Re:Bash-oneliner: A collection of handy Bash one-liners and ... by bradknowles on Wednesday May 04, 2022 @03:22AM (#31257690)
If you want to claim broad compatibility, you can't just look at the latest distributions. You have to look at OSes other than Linux. You have to look at older versions of OSes, too. And don't forget the billions of embedded and handheld devices, too.
Re:Bash-oneliner: A collection of handy Bash one-liners and ... by gnubison on Thursday May 05, 2022 @12:43PM (#31275603)
> You have to look at older versions of OSes, too.

Perl 5 was released in 1994. It is incredibly portable. If you have a system that legitimately has Perl 4, I would love to hear about it, but …

Re:Bash-oneliner: A collection of handy Bash one-liners and ... by gnubison on Tuesday May 03, 2022 @05:54PM (#31254114)
Perl more common than vi? The study you’re remembering probably didn’t include POSIX utilities.
Re:Bash-oneliner: A collection of handy Bash one-liners and ... by mdaniel on Tuesday May 03, 2022 @06:04PM (#31254204)
With the full understanding that "docker images" are their own special little things:

    $ docker run --rm ubuntu:22.04 bash -c 'command -v ex; command -v ed; command -v vi; command -v perl;' 
    /usr/bin/perl
and the same result for "debian:stable"

---

edit: I just realized that's because apt is _written in_ perl, but tomato, tomahto, and it may very well be that they picked perl for that same universal-binary reason

Re:Bash-oneliner: A collection of handy Bash one-liners and ... by gnubison on Wednesday May 04, 2022 @09:36AM (#31260175)
Huh, interesting.