Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Linux Command Line Chapter 26

Similar presentations


Presentation on theme: "The Linux Command Line Chapter 26"— Presentation transcript:

1 The Linux Command Line Chapter 26
Top Down Design Prepared by Dr. Reyes, New York City College of Technology

2 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.

3 Top Down Design Instructions to buy food Get in car. Drive to market.
Park car. Enter market. Purchase food. Return to car. Drive home. 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.

4 Simpler form (preferred)
Shell Functions Shell functions - “mini-scripts” that are located inside other scripts and can act as autonomous programs. Formal form Simpler form (preferred)

5 Sample Script with Functions

6 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. Use keyword local in front of the variable After that, in a separate line assign a value to the variable

7 Example Using Local Variables


Download ppt "The Linux Command Line Chapter 26"

Similar presentations


Ads by Google