How it works...

The creation of mytree.sh is a trivial task, but the logic inside follows recursive functions. There is also the concept of ${CURRENT_LVL}, which is used to produce the number of periods (or levels) deep the script is from its original starting point: parentdir. In each directory, we create a for loop to test each file/directory inside of it. The logic tests whether the entry is either a file or a director. If it is a directory, we increment ${CURRENT_LVL} and then recursively execute the same logic inside of the recursive_tree function until done and then return. If the logic is a file, we merely print out and continue. The tab_creator function makes the variable string for the periods based on ${CURRENT_LVL} and concatenation. ...

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.