Keeping scripts brief and simple

The ideal shell script is a relatively short one, because shell script has such limited support for concepts such as variable scope, no support for a library or module system for robust packaging, a lot of global state of various kinds, and very limited data typing.

Instead of trying to write one very long program that does many things, follow the Unix tradition of writing shorter, smaller programs that do one thing each, and that do that thing very well.

If you find your Bash program is becoming too large and unwieldy, and you can't simplify it, consider translating it to Perl, Python, or a similar general-purpose program instead. This is quite normal; shell script has been used since its earliest days as ...

Get Bash Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.