How it works...

After running the two scripts in this recipe, we can see a few items emerge (especially if we compare the built-in Bash functionality for searching, replacing, and substrings).

  1. After executing some-strs.sh, we can see the following output in the console:
$ bash ./some-strs.sh First character 1First three characters 123Third character onwards 4567890asdfghjklForth to sixth character 456Last character by itself lRemove last character only 1234567890asdfghjk

At this point, we have seen the echo command used several times, but the -n flag means that we should not automatically create a new line (or carriage return). The <<< re-direct for inputting values as a string has also been previously used, so this should not be new information. ...

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.