Difference between revisions of "Tutorial10: Shell Scripting - Part 1"

From CDOT Wiki
Jump to: navigation, search
(KEY CONCEPTS)
(Creating & Executing Shell Scripts)
Line 59: Line 59:
 
===Creating & Executing Shell Scripts===
 
===Creating & Executing Shell Scripts===
  
x
+
It is recommended to plan out on a piece of paper the purpose of the shell script.<br>You can do this by creating a simple IPSO diagram (stands for INPUT, PROCESSING, STORAGE, OUTPUT).<br>First, list the INPUTS into the script (eg. prompting user for data, reading data from file, etc), then listing the expected OUTPUTS from the script.<br>Finally, you can listing the steps to process the INPUT to provide the OUTPUT (including file storage).<br>In the case, you start with the diagram, then generate a list of steps that will help you code your shell script.
  
 +
Once you have planned your shell script by listing the sequence of steps in your script, you need to create a file that will contain your Linux commands.
 +
 +
NOTE:  Avoid using filenames of already existing Linux Commands to avoid confusion. Using shell script filenames that include the file extension of the shell that the script will run within is recommended.
  
 
===Using Variables in Shell Scripts===
 
===Using Variables in Shell Scripts===

Revision as of 09:04, 9 July 2020

INTRODUCTION TO SHELL SCRIPTING


Main Objectives of this Practice Tutorial

  • Understand the process for planning prior to writing a shell script.
  • Understand the purpose of a she-bang line contained at the top of a shell script.
  • Setting permissions for a shell script and properly execute a shell script.
  • Understand and use environment and user-defined variables within a shell script.
  • Understand the purpose of control flow statements used with shell scripts.
  • Use the test command to test various conditions.
  • Use the if logic statement and the for loop statement within shell scripts.

Tutorial Reference Material

Course Notes
Linux Command/Shortcut Reference
YouTube Videos
Course Notes:


Shell Scripting
  • Purpose
  • Planning a Shell Script
  • Executing a Shell Script

Variables

  • Environment
  • User Defined
Control Flow Statements
  • Purpose
  • test command
  • if statement
  • for loop
Brauer Instructional Videos:

KEY CONCEPTS

A shell script is a computer program designed to be run by the Unix shell, a command-line interpreter.
The various dialects of shell scripts are considered to be scripting languages.

Reference: https://en.wikipedia.org/wiki/Shell_script

Creating & Executing Shell Scripts

It is recommended to plan out on a piece of paper the purpose of the shell script.
You can do this by creating a simple IPSO diagram (stands for INPUT, PROCESSING, STORAGE, OUTPUT).
First, list the INPUTS into the script (eg. prompting user for data, reading data from file, etc), then listing the expected OUTPUTS from the script.
Finally, you can listing the steps to process the INPUT to provide the OUTPUT (including file storage).
In the case, you start with the diagram, then generate a list of steps that will help you code your shell script.

Once you have planned your shell script by listing the sequence of steps in your script, you need to create a file that will contain your Linux commands.

NOTE: Avoid using filenames of already existing Linux Commands to avoid confusion. Using shell script filenames that include the file extension of the shell that the script will run within is recommended.

Using Variables in Shell Scripts

x


Using Control Flow Statements in Shell Scripts

x

INVESTIGATION 1: CREATING A SHELL SCRIPT


In this section, you will learn how to ...



Perform the Following Steps:

  1. x

In the next investigation, you will ...

INVESTIGATION 2: USING VARIABLES IN SHELL SCRIPTS

In this section, you will learn how to ...


Perform the Following Steps:

  1. x

In the next investigation, you will ...

INVESTIGATION 3: USING CONTROL FLOW STATEMENTS IN SHELL SCRIPTS

In this section, you will learn how to ...


Perform the Following Steps:

  1. x

LINUX PRACTICE QUESTIONS

The purpose of this section is to obtain extra practice to help with quizzes, your midterm, and your final exam.

Here is a link to the MS Word Document of ALL of the questions displayed below but with extra room to answer on the document to simulate a quiz:

https://ict.senecacollege.ca/~murray.saul/uli101/uli101_week10_practice.docx

Your instructor may take-up these questions during class. It is up to the student to attend classes in order to obtain the answers to the following questions. Your instructor will NOT provide these answers in any other form (eg. e-mail, etc).


Review Questions:

  1. x
  2. x
  3. x
  4. x
  5. x
  6. x
  7. x
  8. x