by staticshock · 2y ago · 0 comments
"Built-in commands" showcases [ ] vs [[ ]]. This is not an efficiency win, but a matter of using older POSIX syntax vs more modern and richer bash syntax. The utility of the bash syntax is that it supports nicer operators, such as < > in addition to stuff like -gt / -lt.
"Efficient File Operations" showcases IFS=, which is not used for the sake of efficiency, but to change how the line is tokenized. (And what good is an efficiency claim that's not backed up by any data?)
I did not look too closely, but I suspect the rest of this list is equally eyebrow-raising.
Try a small benchmark to see the results of /usr/bin/printf vs printf. It really makes a difference (not invoking an external program is a huge performance win).
The author is indeed confused though. `test` for example, is also a builtin. You can have an empty PATH= and still invoke printf, test, echo and some few others.
The list is weird.
Some form of builtin list is always on the man pages though.
There's no good way of telling if a builtin exists programatically (for, let's say, feature detection).
There's an almost good way with `{ PATH=; command -v isthisreallife; }` and some shells will provide a `builtin isthisreallife` that you can use without having to nuke the PATH variable.
As a more practical suggestion, I find functionality detection is much less important since I learned to disavow all knowledge of a script when sharing it
Doesn’t the `type` command (technically a builtin) meet your requirements?
This reads like someone's personal cheat sheet more than an informative post.
There are some good suggestions but I'd really like to know why the author has these opinions.