Live data from Hacker News

I wrote an bash enumerator because I was sick of xargs

numerlab.org

151–160 of 202 posts

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

#152
post #134

Earlier quoted context omitted.

Some of these are wrong, as standard shell globs don't traverse directories. For instance the first example should be: ls **/*.sh I think that would work in Bash just as well as using find. But yeah, even in POSIX it feels redundant when we already have find, seq, grep and whatnot.

To be pendantic ls -- **/*.sh Otherwise it will fail if you've got a file named e.g. --help

So, it's essentially argument injection?

I dislike these tools so much, because you need to know all these corner-cases and I don't.

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

#153
post #151

> Or maybe you pipe into xargs and pray your filenames don’t have spaces So they wrote a new tool and posted it on HN before checking the manual about null character termination... Not trustable at all, what a waste of time!

Same thought I had, and that is where I stopped reading. All of these looping/enumerating techniques, including the weirdness with null-terminating strings to get around the shell's inherent treatment of spacing, are muscle memory for anyone that has spent more than 27 minutes in the shell at any point in the last 30 years. Yes it's weird because it's old. Deal with it. Why make yet another tool with yet another set of quirks?

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

#154
post #127

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.

Maybe it is out of habit, but I never managed to get into PowerShell, in fact, I am not at easy with the Microsoft way of doing things, with few exceptions. Too much UNIX I guess. Nushell seems to be based on the PowerShell philosophy of using structured data and not text, not my thing. I really like the UNIX way of using text I/O, it has it flaws but it works for me. But that being said, I still hate bash and all it…

I'm stodgy, but I can't get past how they chose VERB-OBJECT instead of OBJECT-VERB. get- is useless. MSFT knew tab-completion would be a thing, yet they made it useless.

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

#155
post #118

I lol'd, but do you think this is valid? https://github.com/wallach-game/bashumerate/pull/1/files to me looks like a right solution, even if I was also tired of writing for loops by hand usually

Some of these are wrong, as standard shell globs don't traverse directories. For instance the first example should be: ls **/*.sh I think that would work in Bash just as well as using find. But yeah, even in POSIX it feels redundant when we already have find, seq, grep and whatnot.

But `ls -print0` is not an option;

  set -x
  mkdir test; cd "$_"
  touch "test "$'\n'"12.txt"
  ls
  for name in `ls`; do echo "$name"; done
  find
  find . -exec echo {} \;
  find . -print0
  find . -print0 | xargs -n 1 -0 echo
  #
  find . -print0 | el -0 -v -x echo
  find . -print0 | el -0 -v -x echo "{0} #"
  find . -print0 | el -0 -v -x echo '"{0}" #'
  find . -print0 | el -0 -x sh -x -c 'echo "{0} #"'
  
Though, I just realized that this doesn't work yet either:

  find . -print0 | el -0 -x -- sh -c 'set -x: echo "{0} #"'
  
westurner/dotfiles/scripts/el: "edit lines" https://github.com/westurner/dotfiles/blob/master/scripts/el...

`el -v/--verbose` is useful because it prints each input; though, I might not have written `el` if I had been aware of `xargs -n/--max-args=1`

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

#156
post #149

Earlier quoted context omitted.

To support your recommendation and redress the strawman the article postulates, the post's author could have replaced: find . -name '*.log' | xargs rm With: find . -name '*.log' -print0 | xargs -0 rm

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?”

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

#157

There's room for so much more innovation in the shell space. Microsoft did it with PowerShell - Linux seems to be stuck in the 1980s. You do have newer shells like fish, but they seem to only mess with the on-screen layout of the command prompt (while being stupid enough to still run within a terminal) and not the commands themselves. I wonder if the generation one or two before mine grew up without shells and then h…

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.

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

#158

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.

As others have pointed out throughout the thread, the reason we defend the skills is that there’s a high likelihood that these tools will always be available on any machine; PowerShell and nushell, not so much.

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

#159
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

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

#160

> Or maybe you pipe into xargs and pray your filenames don’t have spaces: > find . -name '*.log' | xargs rm No need for prayer: find . -name '*.log' -print0 | xargs --null rm That uses null as a delimiter instead of linebreaks.

Related: I wish there were a portable way for xargs to treat newlines as delimeters but not other spaces. Since 99.9% of the time that's what you want. (GNU's has this with -d/--delimiter, but BSD's, and thus macOS's, doesn't.)

--null/-0 is portable and helps, but it means the input has to be NUL-delimited, which is... rare. Sure, find has -print0 but (a) I wish I didn't need to do that, and (b) sometimes it's nice to just pipe `ls` output into xargs, without a `... | while read i; do echo -ne "${i}\0"; done | ...` kludge in the pipeline.

Because spaces in filenames is just common enough to be something that will bite you eventually, but newlines in filenames are a straight evil that you can basically always say is the filename's fault.

Post reply on HN