Live data from Hacker News

I wrote an bash enumerator because I was sick of xargs

numerlab.org

171–180 of 202 posts

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

#171

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 with them. So it's best to know all the edge cases before you do stuff you don't want to do. And yes, you could always install another shell. But that brings another dependency and opens up another can of worms. In professional environments it's not really an option to have the next exotic language.

It's like having a tmux.conf on your local machine that configures tmux exactly the way you want it. Nice to have but the moment you touch any of the other billions of systems out there that run the default configuration, you might be lost because you never learned the default and only use your modified version.

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

#172
post #128

Earlier quoted context omitted.

If you do not have -0 options in your xargs/find, I wonder if you will have those extensions in your awk/sed. Perl is a different story.

I think the parent was referring to using awk/sed to do the equivalent of: find ... | tr '\n' '\0' | xargs -0 ... I.e., a blind replacement without the tool having any particular semantic understanding of what it's translating. That still requires your xargs to have -0 support, though, and I'd be surprised to have that without the corresponding option on find. But I've done this before when feeding xargs from somethi…

It is also built on the assumption that filenames never contain newlines, which is wrong in general.

It's baffling to me that POSIX allows non-printable characters in file names, but here we are. Surely they had a reason for this decision.

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

#173
post #127

Earlier quoted context omitted.

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.

Get-AD* is less useless, though? modules should have prefixes! (except for Exchange/ExchangeOnlineManagement who have Get-User and Get-Group, because fuck you apparently)

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

#174

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.

I haven't had to admin any BSD systems, so am happy with choosing Bash. Presumably posix-compliant scripts would be used to also cope with BSD systems.

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

#175

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.

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 do…

  for name in `ls`; do echo "$name"; done
is an unportable and expensive way to write

  for name in *; do printf '%s\n' "$name"; done
but you could also just

  printf '%s\n' *

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

#176

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'm sure it's essentially a familiarity thing, but PowerShell and nushell is way too much typing for me.

I can't comment on nushell, but a CLI shell that uses frequent capitalisation and the 2nd furthest printable character from the home row in every 'verb' is just hilarious.

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

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

  printf 'silent data loss' | while read l; do printf '%s\n' "$l"; done
though at the point I need to write

  while IFS= read -r line || [ -n "$line" ]; do
    printf '%s\n' "$line"
  done
I'll use a different language.

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

#178

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'm just replying reflexively because suggesting Powershell on Linux is an abomination, and because I didn't know about nushell, and it looks awesome. I wonder why the documentation is still that incomplete, though.

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

#179
> enumerate -r 1 10 -- 'printf "%02d\n" {}'

The printf zero-padding should be a built-in feature, as dealing with lots of filename structures and date structures needs zero-padding.

I often end up doing things like "for i in $(seq -w 1 100); do.." in bash.

My preference would actually be that -r does automatic zero-padding to fit the widest number that will come out of the range, and another variant like -R would suppress that behavior; but it could also be an optional switch.

It might also be nice to have the code recognize when start is greater than end, like -r 10 1, and support backwards-counting.

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

#180

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

Post reply on HN