Live data from Hacker News

I wrote an bash enumerator because I was sick of xargs

numerlab.org

181–190 of 202 posts

Re: I wrote an bash enumerator because I was sick of xargs

#181

In this thread: bash experts with arcane knowledge, unintentionally demonstrating how awful bash is. The obvious solution would be to use something more sane, like PowerShell or nushell, but instead old experts will always defend the skills they have honed for years, while criticizing anything that's different.

I like Bash for its portability and pretty much no other reason. That one attribute of it is pretty hard to replicate with any other tool, at least over short time horizons

Re: I wrote an bash enumerator because I was sick of xargs

#182

In this thread: bash experts with arcane knowledge, unintentionally demonstrating how awful bash is. The obvious solution would be to use something more sane, like PowerShell or nushell, but instead old experts will always defend the skills they have honed for years, while criticizing anything that's different.

No, there are two problems here: 1. Things have developed over time. Bash and other shells weren't always this way. If you have ever touched different shells, awk, sed and so on and then touch perl you see how it is basically just the glue between the other tools put into one language. 2. The majority of scripts is written in sh or bash. So these shells won't go away anytime soon and any newcomer will be confronted w…

This is very true. It's why I try to keep my configs as close to default as reasonable because I know I'll be touching strange machines so best to know how it works.

Possibly more for DevOps than a dev.

Re: I wrote an bash enumerator because I was sick of xargs

#183

Earlier quoted context omitted.

Yes, Bash is filled with footguns and is awful due to that. However, it's still incredibly useful as it's everywhere and has a far greater lifespan than almost anything else. You can write scripts in PowerShell or nushell, but then find that twenty years later they're no longer usable or you find a twenty year old machine that won't have PowerShell/nushell installed. It's not so much about defending arcane scripting…

You won't find bash on BSD unless someone installed it.

Possibly why cloud servers are 85% Linux, 14% Windows and 1% Other (including BSD).

My main shell isn't even bash, I go with zsh, but if I'm writing a script for general use I go with bash.

Re: I wrote an bash enumerator because I was sick of xargs

#184

In this thread: bash experts with arcane knowledge, unintentionally demonstrating how awful bash is. The obvious solution would be to use something more sane, like PowerShell or nushell, but instead old experts will always defend the skills they have honed for years, while criticizing anything that's different.

I always avoid Bash I prefer Almquist (ash), eg., NetBSD sh, Debian sh with tab completion, busybox ash, etc. Powershell must be slow and/or bloated like Bash; someone wrote xargs in C++ for Windows: https://github.com/idigdoug/TextTools/tree/main/wargs

Bash is not the default scripting shell on Debian

Given that its manpage states that Bash is slow, perhaps it is not well-suited to be a scripting shell (cf. an interactive shell)

Re: I wrote an bash enumerator because I was sick of xargs

#185
> Or maybe you pipe into xargs and pray your filenames don’t have spaces

Or maybe use: `find ... -print0 | xargs -0 ...`

I guess you're still hoping your filenames don't contain an ASCII NUL, although that's a fairly reasonable assumption for all but the most paranoid use-cases.

Re: I wrote an bash enumerator because I was sick of xargs

#186

In this thread: bash experts with arcane knowledge, unintentionally demonstrating how awful bash is. The obvious solution would be to use something more sane, like PowerShell or nushell, but instead old experts will always defend the skills they have honed for years, while criticizing anything that's different.

Yes, Bash has no place in modern software engineering. The only reasons people still use it are historical and laziness. If it was invented today, professionals would cringe at it.

The submission begins with these examples:

    for f in *.txt; do
      wc -l "$f"
    done
   
      Or this?
   
    find . -name '*.sh' -exec wc -l {} +
   
      Or maybe you pipe into xargs and pray your filenames don't have spaces:
   
    find . -name '*.log' | xargs rm
Is that "software engineering"

Looks more like "system administration"

Re: I wrote an bash enumerator because I was sick of xargs

#187
post #67

> Or maybe you pipe into xargs and pray your filenames don’t have spaces… Always use -0. Most gnu utilities support it. It makes them put a null byte after every filename instead of a newline. Completely eliminates the problem of dealing with whitespace in the filenames.

No dependency on GNU required anymore, POSIX 2024 supports it: https://blog.toast.cafe/posix2024-xcu#the-null-option

Neat, I didn’t know that! Even cooler that they’ve started to change all the core utilities to error out instead of creating a file with a newline character in it.

Re: I wrote an bash enumerator because I was sick of xargs

#188
post #136
post #7

Not sure I see the point of this. Remembering a bunch of options on one tool is no better than a bunch of tools/constructs? Especially if the latter are useful elsewhere. And it can't be used for scripts unless you start shipping it alongside, which… nah. Just go with foo | while read X; do bar "$X"; done

Yes, I think the author is just showing their ignorance, not actually doing anything about that ignorance, and re-inventing the wheel: $ find /path -name "*.pdf" -print0 | xargs -0 -I {} echo "Processing: {}" # handles paths properly, obviates the need to write anything new whatsoever Seriously kids, learn your tools and check yourself before you wreck yourselves writing tools that really, really don't need to be wri…

find print0 with xargs 0 is such an awesome combination. One day I'll remember to use it instead of piping into while read ln; do ...

Re: I wrote an bash enumerator because I was sick of xargs

#189
post #149

Earlier quoted context omitted.

This one doesn't need xargs. find . -name '*.log' -delete

THANK YOU. I kept nodding along to all of the xargs comments, thinking “sure, but what about the even easier solution?”

As well as find has an -exec param to perform things one at a time or all with the same command by using a slash semicolon or a plus sign respectively:

  #order files from different levels in a file hierarchy by size:
  find . -type f -maxdepth 1 -exec ls -hlrS {} +

  #output metadata for each file sequentially
  find . -type f -maxdepth 1 -exec file {} \;

Re: I wrote an bash enumerator because I was sick of xargs

#190

Earlier quoted context omitted.

Shells imo are legacy on legacy, I like bash and zsh, they’re nonsensical but they work. Powershell is undoubtedly saner, but I hate it. I think the whole concept could be rewritten from the ground up to be modern, but reaching critical mass and mvp is too damn difficult, and the majority of mac/Linux users probably don’t want it.

If you build it and it's better, they will come. None of us here are building it.

There are already alternative shells. I think there’s some stuff fairly deeply rooted into gnu that’s an ‘issue’ for rebuilding and turns an effort into a complete redesign, making the whole thing hard to achieve.
Post reply on HN