Earlier quoted context omitted.
find . -maxdepth 1 -name '*.yaml' -print0 | xargs -r0 the_tool >To say "you're holding it wrong" is just folly. Bash is worthy of the same treatment that "A Fractal of Bad Design" gave PHP, and it has no place in anything that wants to call itself engineering. If you have a problem that involves "run a command with a list of parameters but not if the list is empty" and you don't immediately think of `xargs -r`, then…
> If you have a problem that involves "run a command with a list of parameters but not if the list is empty" and you don't immediately think of `xargs -r`, then consider that it's because you don't understand the tools, not because the tools are bad. find has -exec, xargs isn't necessary.
Bashing the Bash – Replacing Shell Scripts with Python (2017)
121–130 of 138 posts
Re: Bashing the Bash – Replacing Shell Scripts with Python (2017)
#122Earlier quoted context omitted.
find . -maxdepth 1 -name '*.yaml' -print0 | xargs -r0 the_tool >To say "you're holding it wrong" is just folly. Bash is worthy of the same treatment that "A Fractal of Bad Design" gave PHP, and it has no place in anything that wants to call itself engineering. If you have a problem that involves "run a command with a list of parameters but not if the list is empty" and you don't immediately think of `xargs -r`, then…
Doesn’t xargs also die at too many files? Fact is, bash manages to have more footguns than goddamn C, which is telling something
No?
Re: Bashing the Bash – Replacing Shell Scripts with Python (2017)
#123Earlier quoted context omitted.
> If you have a problem that involves "run a command with a list of parameters but not if the list is empty" and you don't immediately think of `xargs -r`, then consider that it's because you don't understand the tools, not because the tools are bad. find has -exec, xargs isn't necessary.
`-exec` would run the command for each file separately, which isn't what the original problem wanted, and I didn't want to assume that it would be equivalent.
Re: Bashing the Bash – Replacing Shell Scripts with Python (2017)
#124Earlier quoted context omitted.
> To say "you're holding it wrong" is just folly. Bash is worthy of the same treatment that "A Fractal of Bad Design" gave PHP, and it has no place in anything that wants to call itself engineering. is this a cloud AMD64 opinion that ignores the 2 trillion devices which Gartner predicts will never run python? I recently finished a ~600 lines ash script and the kids at work which just graduated complained that *"Y u n…
How is bash performant? It is literally interpret by lines , and starting a whole process per if statements..
Re: Bashing the Bash – Replacing Shell Scripts with Python (2017)
#125Earlier quoted context omitted.
My preferred way under those conditions would be more along the lines of "see if a safe command fails, do the desired command if not", like: if ls *.yaml > /dev/null; then the_tool *.yaml fi
That only looks simple because we don't know what problem was being solved. Is it really right to not process any files just because one of them just disappeared? In general, situations like this suffer from race conditions and time-of-check/time-of-use problems.
No idea what you mean here, the glob can expand to one or many.
> In general, situations like this suffer from race conditions and time-of-check/time-of-use problems.
I mean, that's a problem in every version presented so far, one that I don't think can be fixed externally without something extra like hardlinking to a new directory, because "the_tool" apparently can't handle missing files and they can go missing when "the_tool" starts up. That's why I didn't even bother.
Re: Bashing the Bash – Replacing Shell Scripts with Python (2017)
#126Earlier quoted context omitted.
We had some problem, roughly, "run a tool on all YAML files in the directory" or something. The first attempt that led to a production outage: (It is late, bash examples are approximate. Don't sweat the syntax.) the_tool *.yaml There weren't any YAML files, so argv[1] was literally "*.yaml", which then wasn't found, leading to errors, etc. shopt -s nullglob the_tool *.yaml (Don't even get me started on how there's sh…
find . -maxdepth 1 -name '*.yaml' -print0 | xargs -r0 the_tool >To say "you're holding it wrong" is just folly. Bash is worthy of the same treatment that "A Fractal of Bad Design" gave PHP, and it has no place in anything that wants to call itself engineering. If you have a problem that involves "run a command with a list of parameters but not if the list is empty" and you don't immediately think of `xargs -r`, then…
Re: Bashing the Bash – Replacing Shell Scripts with Python (2017)
#127Earlier quoted context omitted.
`-exec` would run the command for each file separately, which isn't what the original problem wanted, and I didn't want to assume that it would be equivalent.
It runs them separately if you end the exec with ";", it appends as many as possible to the same command if you end it with "+"
Re: Bashing the Bash – Replacing Shell Scripts with Python (2017)
#128And give a wonderful syntax error.
Re: Bashing the Bash – Replacing Shell Scripts with Python (2017)
#129Earlier quoted context omitted.
> It's also why it won't go away. Python 2 went away in macOS. Bash still exists.
https://www.python.org/downloads/release/python-2718/ There's still a macOS installer for the latest release of Python2.7 (4/20/2020).
[0] Sunsetting Python 2. https://www.python.org/doc/sunset-python-2/
Re: Bashing the Bash – Replacing Shell Scripts with Python (2017)
#130Earlier quoted context omitted.
> It's also why it won't go away. Python 2 went away in macOS. Bash still exists.
Did it really? `/usr/bin/python` invokes Python 2.7.18 on my just-bought Macbook Pro 14 running MacOS 12.2. Maybe that's because I installed the Xcode command line tools?
[0] https://www.macrumors.com/2022/01/28/apple-removing-python-2...