Design Scripts  «Prev  Next»
Lesson 1

Designing more complex scripts

Before you start writing a complex shell script, you should plan what the script will do and how it will do it. This planning is a critical part of designing an effective script in any programming language. Without thinking through your script before you start writing it, you are likely to waste a lot of time and have an inefficient script when you have finished.
By the end of this module you will be able to:
  1. Define a clear script objective
  2. Diagram the flow of control through a script
  3. Decide which types of tests will work best in your script
  4. Test commands before using them in a script
  5. Include error-checking in your script
  6. Create a script that works in multiple shells

How do I define a clear objective for my Unix Shell Script?

Defining a clear objective is an important first step when creating a Unix shell script. Here are some steps you can follow to help you define your objective:
  1. Identify the problem: The first step is to identify the problem you want to solve with your shell script. What is the task that you want your script to accomplish? This could be anything from automating a repetitive task, to processing large amounts of data, to creating backups of important files.
  2. Determine the scope: Once you have identified the problem, it is important to determine the scope of the project. What are the specific requirements for the script? What are the limitations? What are the dependencies?
  3. Define the output: What is the expected output of the script? Do you want the script to generate a report, a file, or just display information on the screen?
  4. Identify the inputs: What inputs will the script need to accomplish its objective? This could be data from files, user input, or data from other programs.
  5. Break down the steps: Once you have identified the inputs and outputs, it is important to break down the task into smaller steps. What are the specific tasks that the script needs to perform in order to accomplish its objective?
  6. Define success: Finally, it is important to define what success looks like for your script. How will you know that your script has accomplished its objective?

By following these steps, you can define a clear objective for your Unix shell script, which will make it easier to develop and test your script, and ensure that it is successful in achieving its intended purpose.