Batch Files More flow of control Copyright © 2003-2016 by Curt Hill.

Slides:



Advertisements
Similar presentations
CST8177 bash Scripting Chapters 13 and 14 in Quigley's "UNIX Shells by Example"
Advertisements

Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Programming Logic and Design Fourth Edition, Introductory
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Shell Basics CS465 - Unix. Shell Basics Shells provide: –Command interpretation –Multiple commands on a single line –Expansion of wildcard filenames –Redirection.
Program Design and Development
CS 497C – Introduction to UNIX Lecture 34: - Shell Programming Chin-Chih Chang
Introduction to Unix – CS 21 Lecture 5. Lecture Overview Lab Review Useful commands that will illustrate today’s lecture Streams of input and output File.
Shell Programming. Shell Scripts (1) u Basically, a shell script is a text file with Unix commands in it. u Shell scripts usually begin with a #! and.
Shell Script Examples.
Ch 111 Chapter 11 Advanced Batch Files. Ch 112 Overview This chapter focuses on batch file commands that allow you to:  write sophisticated batch files.
1 Microsoft Access 2002 Tutorial 5 – Enhancing a Table’s Design, and Creating Advanced Queries and Custom Forms.
Ch 51 Internal Commands COPY and TYPE. Ch 52 Overview Will review file-naming rules.
PMS /134/182 HEX 0886B6 PMS /39/80 HEX 5E2750 PMS /168/180 HEX 00A8B4 PMS /190/40 HEX 66CC33 By Adrian Gardener Date 9 July 2012.
More Command Line Options Pipes, Redirection, Standard files Copyright © 2015 Curt Hill.
The UNIX Shell. The Shell Program that constantly runs at terminal after a user has logged in. Prompts the user and waits for user input. Interprets command.
Shells. A program that is an interface between a user at a terminal and the computers resouces ▫The terminal may be real or an emulator The shell is.
Lecture Set 5 Control Structures Part D - Repetition with Loops.
Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.
1 Functions 1 Parameter, 1 Return-Value 1. The problem 2. Recall the layout 3. Create the definition 4. "Flow" of data 5. Testing 6. Projects 1 and 2.
Command Prompt Chapter 10 Introduction to Batch Files Richard Goldman February 7, 2000.
The Command Line Mostly MS Dos with some UNIX/LINUX Copyright © Curt Hill.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
Shell Programming Any command or a sequence of UNIX commands stored in a text file is called a shell program. It is common to call this file a command.
Chapter Five Advanced File Processing. 2 Objectives Use the pipe operator to redirect the output of one command to another command Use the grep command.
This slide deck is for LPI Academy instructors to use for lectures for LPI Academy courses. ©Copyright Network Development Group Module 9 Basic Scripting.
CREATING TEMPLATES CREATING CUSTOM CHARACTERS IMPORTING BATCH DATA SAVING DATA & TEMPLATES CREATING SERIES DATA PRINTING THE DATA.
Copyright © Curt Hill Stored Procedures In Transact-SQL.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
Copyright Curt Hill Variables What are they? Why do we need them?
Statement Level Flow of Control Iteration Structures Copyright © by Curt Hill.
LIN Unix Lecture 5 Unix Shell Scripts. LIN Command Coordination ; && || command1 ; command2 Interpretation: Do command 1. Then do command.
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
Shell Scripting – Putting it All Together. Agenda Escaping Characters Wildcards Redirecting Output Chaining and Conditional Chaining Unnamed and Named.
1. FINISHING FUNCTIONS 2. INTRODUCING PLOTTING 1.
Copyright Curt Hill The C/C++ switch Statement A multi-path decision statement.
Environment After log in into the system, a copy of the shell is given to the user Shell maintains an environment which is distinct from one user to another.
Scanner Generation Using SLK and Flex++ Followed by a Demo Copyright © 2015 Curt Hill.
Batch Files Weaker form of UNIX shell scripts. Introduction UNIX may use one of several shells The shell is the command interpreter It interacts with.
Batch Files Weaker form of UNIX shell scripts Copyright © by Curt Hill.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
The Process CIS 370, Fall 2009 CIS UMassD. The notion of a process In UNIX a process is an instance of a program in execution A job or a task Each process.
Lesson 6-Using Utilities to Accomplish Complex Tasks.
Copyright © Curt Hill Common Dialogs Easily Obtaining File Names in DevC++ Windows Programs.
Various 2. readonly readonly x=4 x=44 #this will give an error (like what in java?)
Batch Files Flow of Control to Strengthen Copyright © by Curt Hill.
CS 403: Programming Languages Lecture 20 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
1 UNIX Operating Systems II Part 2: Shell Scripting Instructor: Stan Isaacs.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
1 Lecture 8 Shell Programming – Control Constructs COP 3353 Introduction to UNIX.
Chapters 13 and 14 in Quigley's "UNIX Shells by Example"
PowerShell Introduction Copyright © 2016 – Curt Hill.
Introduction to Python
Using SLK and Flex++ Followed by a Demo
Predefined Dialog Boxes
The C++ IF Statement Part 2 Copyright © Curt Hill
Shell Commands Using BASH Copyright © 2017 Curt Hill.
A poorly named Curt Hill utility program
T. Jumana Abu Shmais – AOU - Riyadh
Cmdlets “Command-lets”
More advanced BASH usage
Copyright © – Curt Hill Bash Flow of Control Copyright © – Curt Hill.
Linux Shell Script Programming
The Java switch Statement
PowerShell Flow of Control Copyright © 2016 – Curt Hill.
CST8177 Scripting 2: What?.
Chapter 3 The UNIX Shells
Presentation transcript:

Batch Files More flow of control Copyright © by Curt Hill

Introduction We have already seen the standard commands: –Echo –Using variables –If and GOTO Now we consider some more advanced commands –Looping –Choice Copyright © by Curt Hill

Looping Goto can be used to make loops or an if then else construction –This is exactly how it is done in assembly If we conditional branch to later in the file it is usually an if-like structure If we conditional branch earlier then it is making a loop There is one easier way to make loop Copyright © by Curt Hill

For Loops The FOR allows us to run the same command many times The many times is once each for each item in a group or set This is a much more sophisticated loop –Likely added later Copyright © by Curt Hill

The FOR The general format of the for is: FOR var IN set DO cmd where: –FOR, IN and DO are just keywords –var is a variable such as %c –From the command prompt it is %c –set is a parenthesized list of things, usually files Copyright © by Curt Hill

Sets Usually a file specification with wildcards –(*.*) is the set of all files in this directory May have multiple things separated by blanks –(abc.dat xyz.doc stuff.jun) We may have a combination of files with and without wildcards –(abc.* dat??.sss $*.* last.one) Copyright © by Curt Hill

More on For The control variable (the %x or %x) will become each file in this list before being substituted into the command The cmd is a single command usually with replaceable parameter It may be a executable program or bat file For each item in the set we get one execution of the command Copyright © by Curt Hill

For Continued The replaceable parameter should make each execution of the command different Parameters and file specifications may be constant or replaceable parameters Type command does not allow wildcards Execute a type that uses wildcards Type out all files of extension.lst: for %f in (*.lst) do type %f Copyright © by Curt Hill

Restrictions and exceptions The things in the set do not have to be files, but that is usually what they are –Example: execute ls with two different parameters: for %p in (x d) do ls /%p –Execute ls twice: ls /x ls /d Copyright © by Curt Hill

Redirection Redirection and piping may be used, but it does not always do what you want Redirection: for %f in (*.lst) do type %f >stuff.lis –Each separate copy of type z.lst will be redirected to stuff.lis –Thus only the last one is saved Copyright © by Curt Hill

Choice Choice is a batch command that asks the user to choose a character then signals which was typed This allows a batch file to get user input from the console The chosen character then corresponds to the ERRORLEVEL returned There are several option letters that make it work –We see these on next screen Copyright © by Curt Hill

Choice options /C - the characters available –These are not quoted –First one will be signaled by ERRORLEVEL 1, second by 2 –Default is YN –You cannot type something not in the list /CS makes it case sensitive /M – is the message –This is quoted Copyright © by Curt Hill

More options /T – timeout seconds /D – default to return if timeout /N – hide the choices Copyright © by Curt Hill

Example Copyright © by Curt Hill choice /c ABCD /m "Choose letter" if errorlevel 4 goto d if errorlevel 3 goto c if errorlevel 2 goto b if errorlevel 1 goto a goto endit :a echo A was chosen goto endit :b

Finally We should now do some examples We should have a copy of lc, the line counter Lets count lines of C++ code in a single directory Copyright © by Curt Hill