How it works...

This recipe is a bit iterative, but it should re-iterate (pardon the pun) to demonstrate that Bash has a fair number of functionalities built-in to manipulate strings or any structured data. There is a basic assumption though and that is based on many OSes using C programs:

  • A string is an array of characters
  • Characters such as ',' are the same as any other character 
  • Therefore, we can evaluate or test for the existence of a character to separate fields from lines and even use this to build arrays

Now, reviewing the steps in this recipe:

  1. After running the script, we have the following output in the console:
$ builtin-str.shfirst character 1first three characters 123third character onwards 4567890asdfghjklforth to sixth ...

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.