Presentation is loading. Please wait.

Presentation is loading. Please wait.

Shell Scripting Introduction. Agenda What is Shell Scripting? Why use Shell Scripting? Writing and Running a Shell Script Basic Commands -ECHO - REM.

Similar presentations


Presentation on theme: "Shell Scripting Introduction. Agenda What is Shell Scripting? Why use Shell Scripting? Writing and Running a Shell Script Basic Commands -ECHO - REM."— Presentation transcript:

1 Shell Scripting Introduction

2 Agenda What is Shell Scripting? Why use Shell Scripting? Writing and Running a Shell Script Basic Commands - @ -ECHO - REM - TITLE - COLOR - PAUSE

3 Shell Scripting are text files of CLI commands must have the CMD or BAT extension execute a batch file by typing its name at the C:\> In Vista, you can execute batch files only from your profile directory C:\users\profileName, unless authenticated as administrator you can use the “Open Command Window Here” by holding the Shift KEY and right clicking on any folder in Explorer you can execute a batch file as administrator by holding the Shift key and right clicking on the executable and choosing “Run as Administrator” dialog box

4 Why use Shell scripting? Automate repetitive tasks which don’t warrant the time to write a C, C++ program Customizing desktop environment Copying\moving directory trees Renaming groups of files Run a series of procedures with one command Gathering status information and preparing a printed report Create menus and interactive programs to simply the UI Shell scripting is an essential skill of all Windows users to solve programming problems and improve efficiency of the OS

5 Basic Shell Commands ECHO turns system prompt output on or off and displays messages ECHO ON turns system prompt messages on ECHO OFF turns system prompt messages off ECHO. Creates a blank line @ suppresses the system prompt for a line PAUSE stops execution until user input CLS clears the screen REM prevents execution of a line. Good for comments and debugging

6 Writing a Shell Script  Use any text editor and save the file with a.cmd  Good programming requires good documentation  Name of file.cmd  Author of the file  Date Last Modified  Purpose of the file  Requirements  White space can be used to make the script easier to read – has not effect on the running of the script  Writing commands in uppercase makes debugging easier, but is not required

7 Writing a Simple Script Stops system messages Documentation Clears screen Displays message Gives user opportunity to stop execution Stops execution until user presses any key Built in function to stop script execution

8 Saving Your Script

9 Running Your Script Command line input: Command line output:

10 @ECHO OFF, ECHO Example Create the following Shell script file, name it “greeting.cmd”

11 ECHO. Example Used to create a blank line to improve appearance of the output

12 REM Example Used to add comments to make the code more readable

13 CLS Example Used to clear the screen -- prompt at the top of the window

14 Title Example Used to add text to the title bar

15 Color Example Changes foreground and background colour

16 PAUSE Example Used to temporarily stop script execution

17 Replaceable Parameters A replaceable parameter is a “placeholder” for information entered on the command line and inserted by the command interpreter into the script during run time Unnamed Replacement Parameters Use %1, %2, %3, %4, %5, %6, %7, %8, %9

18 Unnamed Replacement Parameters Names are “hardwired” in the script – no flexibility No user input before script runs – no dynamic changes Changes to script must be retyped – thus, error prone

19 Unnamed Replacement Parameters Statements are not “hardwired” – gives flexibility User input on the CLI – allows dynamic changes No retyping of code – thus, less error prone

20 Unnamed Replacement Parameters


Download ppt "Shell Scripting Introduction. Agenda What is Shell Scripting? Why use Shell Scripting? Writing and Running a Shell Script Basic Commands -ECHO - REM."

Similar presentations


Ads by Google