CHAPTER 7String Manipulation

In the Bourne shell, very little string manipulation was possible without resorting to external commands. Strings could be concatenated by juxtaposition, they could be split by changing the value of IFS, and they could be searched with case, but anything else required an external command.

Even things that could be done entirely in the shell were often relegated to external commands, and that practice has continued to this day. In some current Linux distributions, you can find the following snippet in /etc/profile. It checks whether a directory is included in the PATH variable:

if ! echo ${PATH} |grep -q /usr/games then   PATH=$PATH:/usr/games fi

Even in a Bourne shell, you can do this without an external command: ...

Get Pro Bash Programming: Scripting the GNU/Linux Shell 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.