Making Your BASH Programs Run Faster |

Making Your BASH Programs Run Faster

Use BASH builtins whenever possible

Forking out a sub process is expensive, therefore, try to use the builtin features whenever possible. For instance, using the builtin String manipulation features in BASH can save you many seconds (or even minutes!) on your running time of larges BASH programs.

Instead of file_name=$(basename "${file}"), do:


Instead of dir=$(dirname "${file}"), do:


With just these two enhancements, I reduced the running time of one BASH program from over 8 minutes to under 4 minutes. More than twice as fast!

gmail torstein.k.johansen @ gmail ~ twitter @torsteinkrause ~