3 ms·
Bash is all about shelling out: it's a shell. I would happily use grep here, and if I had an array: printf "%s\0" "$@" | grep -qz needle > much more perform
by falsedan 9y ago
Bash is all about shelling out: it's a shell. I would happily use grep here, and if I had an array:
printf "%s\0" "$@" | grep -qz needle
> much more performant
I believe that performance-critical code shouldn't be written in bash. I have seen pipelines be much faster than tweaked bash functions, simply because they run in parallel & thus the cost of forking is paid once, up-front.
- jstimpfle 9y agoI agree with you. I think we are just speaking about different things. I was more thinking about the things that happen in a configure script, for example. Not a "hoot loop" like a big grep over millions of lines or something. There are situations in shell code where the difference between a case-match or string-suffix-replace written in shell and a process spawn matters. Not only because forking a process for one simple string operation is wasteful (cost: about 1ms), but also because of the semantic problems that come with child processes (error handling).