Write a command called directory which will present a visual representation of the user’s directory structure, starting from their $HOME directory and passing through each directory in the hierarchy.? The screen should be cleared before presenting the output, and the user should be offered the command prompt after the display has been given.
The hierarchical level of each directory needs to be represented by the length of an indent string so that the user can immediately see which directories are under which parent directories.? You should also add a number at the end of each directory line.? ?
Write additional features into the standard directory program so that after the directory structure has been displayed to the user, the user may jump to a given directory by specifying a given argument.
The behaviour of directory should be amended so as to fulfill the following:
i) when directory is executed with more than one argument, a non-numeric argument, or a number greater than the highest number in the directory structure output display, correct usage is displayed.
ii) when directory is executed with a single argument of 0, the directory structure is displayed.
iii) when directory is executed with a number within the range 1-<max-number-from-dir-structure-display> (ie in the example below 1-14), the user is automatically taken to the corresponding directory, the name of which is displayed.
Follows is an example of the result of directory 0 being entered at the command prompt.
## Deliverables
Using these tools create a bash script to do the following below.
? echo
? if / test
? loops
? clear
? arrays
? functions (esp concept of recursion)
? how the path works
? variable assignment
? let
? directory structures
? ls
The directory command
Write a command called directory which will present a visual representation of the user’s directory structure, starting from their $HOME directory and passing through each directory in the hierarchy.? The screen should be cleared before presenting the output, and the user should be offered the command prompt after the display has been given.
The hierarchical level of each directory needs to be represented by the length of an indent string so that the user can immediately see which directories are under which parent directories.? You should also add a number at the end of each directory line.? See the example below for the presentation of the output:
-(0)
/home/<user-name>-(1)
..........a-(2)
....................Flat-(3)
..............................Database-(4)
..............................unix-(5)
........................................dir1-(6)
....................taxes-(7)
....................Database-(8)
..............................course-(9)
..............................force-(10)
........................................exercises-(11)
..................................................Compose10-(12)
..................................................Compose11-(13)
..................................................Compose12-(14)
The example above shows that directly under the home directory, there is a single directory ‘a’ which contains ‘Flat’, ‘taxes’ and ‘Database’.? Under ‘Flat’ there is ‘Database’ and ‘unix’.
Note the ‘empty’ directory above the output with the number 0.? You should place the first element of your list of directories as element 0, and the home directory as element 1. All subsequent directories need to be numbered sequentially, irrespective of their hierarchical placement, as shown above.
Configuration
Allow the developer to specify which character should be used as an indent marker (in the example above, this is a ‘.’ Character), and how many characters should be used for each indent level; this should be done in a convenient place in the script, so that it can be easily changed.
Write additional features into the standard directory program so that after the directory structure has been displayed to the user, the user may jump to a given directory by specifying a given argument.
The behaviour of directory should be amended so as to fulfill the following:
i) when directory is executed with more than one argument, a non-numeric argument, or a number greater than the highest number in the directory structure output display, correct usage is displayed.
ii) when directory is executed with a single argument of 0, the directory structure is displayed.
iii) when directory is executed with a number within the range 1-<max-number-from-dir-structure-display> (ie in the example below 1-14), the user is automatically taken to the corresponding directory, the name of which is displayed.
Follows is an example of the result of directory 0 being entered at the command prompt.
-(0)
/home/<user-name>-(1)
..........a-(2)
....................Flat-(3)
..............................Database-(4)
..............................unix-(5)
........................................dir1-(6)
....................taxes-(7)