Exercises
1. | The dirname utility treats its argument as a pathname and writes to standard output the path prefix, that is, everything up to but not including the last component. Thus
dirname a/b/c/d writes a/b/c to standard output. If path is a simple filename (has no / characters), dirname writes a . to standard output. Implement dirname as a Z Shell function. Make sure that it behaves sensibly when given such arguments as /. |
2. | Implement the basename utility, which writes the last component of its pathname argument to standard output, as a Z Shell function. For example,
zsh % basename a/b/c/d
writes d to standard output. |
3. | The GNU/Linux basename utility has an optional second argument. If you type
basename path suffix basename removes the ... |
Get A Practical Guide to Red Hat® Linux® 8 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.