Striping/altering/sorting/deleting/searching strings with Bash only

So far, we have seen inkling of the power of commands available in Linux, and some of these are among the most powerful: sed and grep. However, while we can easily use these commands together, sed by itself or even using another very useful command called awk, we can leverage Bash itself to shave time and reduce external dependencies in a portable way!

So, how can we do this? Let's begin with a few examples using this Bash syntax:

#!/bin/bash# Index zero of VARIABLE is the char 'M' & is 14 bytes longVARIABLE="My test string"# ${VARIABLE:startingPosition:optionalLength}echo ${VARIABLE:3:4}

In the preceding example, we can see a special way of calling special substring functionality ...

Get Bash Cookbook 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.