Pure Bash Bible
Minimum price
Suggested price

Pure Bash Bible

A collection of pure bash alternatives to external processes.

About the Book

A collection of pure bash alternatives to external processes and programs. The bash scripting language is more powerful than people realise and most tasks can be accomplished without the need for or dependence on external programs.

Calling an external process in bash is expensive and excessive use will cause a noticeable slowdown. Scripts and programs written using built-in methods where applicable will be faster, require less dependencies and afford a better understanding of the language itself.

The content of this book provides a reference for solving problems encountered when writing programs and scripts in bash. All examples are in function format showcasing how to incorporate these solutions into code.

Pure Bash Bible is Open Source under the MIT license and is available freely here: https://github.com/dylanaraps/pure-bash-bible

About the Author

Dylan Araps
Dylan Araps

Dylan Araps is an Open Source Developer from Melbourne Australia. He developed a passion for Open Source and Free Software at a very young age producing a number of successful projects over the years. He left school at 14 to concentrate and expand his knowledge of Linux, programming and other related skills.

His projects have been widely used and continue to evolve and generate interest within the Unix and Linux community. His projects are available online at GitHub forever free and open to collaboration.


Table of Contents

    • Trim leading and trailing white-space from string
    • Trim all white-space from string and truncate spaces
    • Use regex on a string
    • Split a string on a delimiter
    • Change a string to lowercase
    • Change a string to uppercase
    • Trim quotes from a string
    • Strip all instances of pattern from string
    • Strip first occurrence of pattern from string
    • Strip pattern from start of string
    • Strip pattern from end of string
    • Check if string contains a sub-string
    • Check if string starts with sub-string
    • Check if string ends with sub-string
    • Reverse an array
    • Remove duplicate array elements
    • Random array element
    • Cycle through an array
    • Toggle between two values
    • Loop over a range of numbers
    • Loop over a variable range of numbers
    • Loop over an array
    • Loop over an array with an index
    • Loop over the contents of a file
    • Loop over files and directories
    • Read a file to a string
    • Read a file to an array (by line)
    • Get the first N lines of a file
    • Get the last N lines of a file
    • Get the number of lines in a file
    • Count files or directories in directory
    • Create an empty file
    • Extract lines between two markers
    • Get the directory name of a file path
    • Get the base-name of a file path
    • Assign and access a variable using a variable
    • Text Colors
    • Text Attributes
    • Cursor Movement
    • Erasing Text
    • Indirection
    • Replacement
    • Length
    • Expansion
    • Case Modification
    • Default Value
    • Ranges
    • String Lists
    • Assignment
    • Arithmetic
    • Bitwise
    • Logical
    • Miscellaneous
    • Simpler syntax to set variables
    • Ternary Tests
    • Do something on script exit
    • Ignore terminal interrupt (CTRL+C, SIGINT)
    • React to window resize.
    • Do something before every command.
    • Do something when a shell function or a sourced file finishes executing
    • Disable Unicode
    • Shebang
    • Command Substitution
    • Function Declaration
    • Get the location to the bash binary
    • Get the version of the current running bash process
    • Open the user’s preferred text editor
    • Get the name of the current function
    • Get the host-name of the system
    • Get the architecture of the Operating System
    • Get the name of the Operating System / Kernel
    • Get the current working directory
    • Get the number of seconds the script has been running
    • Get a pseudorandom integer
    • Get the terminal size in lines and columns (from a script)
    • Get the terminal size in pixels
    • Get the current cursor position
    • Convert a hex color to RGB
    • Convert an RGB color to hex
    • Shorter for loop syntax
    • Shorter infinite loops
    • Shorter function declaration
    • Shorter if syntax
    • Simpler case statement to set variable
    • Use read as an alternative to the sleep command
    • Check if a program is in the user’s PATH
    • Get the current date using strftime
    • Generate a UUID V4
    • Progress bars
    • Get the list of functions in a script
    • Bypass shell aliases
    • Bypass shell functions

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

80% Royalties. Earn $16 on a $20 book.

We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earnedover $13 millionwriting, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub