
Linux Command Line Design Principles
Learn about top-down design, shell functions, global vs local variables, and the importance of breaking down complex tasks into smaller steps in Linux command line scripting.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
The Linux Command Line Chapter 26 Top Down Design Prepared by Dr. Reyes, New York City College of Technology
Top Down Design As scripts get larger and more complex, they become more difficult to design, code and maintain. It is often a good idea to break large, complex tasks into a series of small, simple tasks.
Top Down Design Instructions to buy food 1. Get in car. 2. Drive to market. 3. Park car. 4. Enter market. 5. Purchase food. 6. Return to car. 7. Drive home. 8. Park car. 9. Enter house. Subtasks for step 3, 8 Park Car 1. Find parking space. 2. Drive car into space. 3. Turn off motor. 4. Set parking brake. 5. Exit car. 6. Lock car.
Shell Functions Shell functions - mini-scripts that are located inside other scripts and can act as autonomous programs. Simpler form (preferred) Formal form
Sample Script with Functions
Global vs Local Variables Global variables variables that maintain their existence throughout the program and can be accessed anytime by any function. Local variables variables defined inside shell functions and are only accessible within the shell function in which they are defined and cease to exist once the shell function terminates. o Use keyword local in front of the variable o After that, in a separate line assign a value to the variable
Example Using Local Variables