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!
I wrote an bash enumerator because I was sick of xargs
151–160 of 202 posts
Re: I wrote an bash enumerator because I was sick of xargs
#152Earlier 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
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> 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!
Re: I wrote an bash enumerator because I was sick of xargs
#154In 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…
Re: I wrote an bash enumerator because I was sick of xargs
#155I 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.
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
#156Earlier 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
Re: I wrote an bash enumerator because I was sick of xargs
#157There'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.
Re: I wrote an bash enumerator because I was sick of xargs
#158In 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.
Re: I wrote an bash enumerator because I was sick of xargs
#159> 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.
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.
--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.