File Name Stripping

Sometimes you want to modify a path name in a script to strip off unneeded parts. With the Bourne shell, you can use the basename(1) command to return only the file name, and the dirname(1) command to return only the directory prefix. The Korn and C shells provide a built-in way for you to modify path names.

Korn Shell Path Stripping

The Korn shell provides pattern-matching operators, shown in Table 81, that you can use to strip off components of path names.

Table 81. Korn Shell Pattern-Matching Operators
Operator Description
${variable# pattern} Delete the shortest part at the beginning of the variable that matches the pattern and return the rest.
${variable## pattern} Delete the longest part at the beginning of the variable ...

Get Solaris™ 8 Advanced System Administrator's Guide, Third Edition 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.