Linux Constructs. The default separator character between each integer is a newline, but this can be changed with the -s option.
|
|
- Elvin Cannon
- 7 years ago
- Views:
Transcription
1 Linux Constructs Relational Operators -eq - Equal to -lt - Less than -gt - Greater than -ge - Greater than or Equal to -le - Less than or Equal to File related tests -f le - True if le exists and is a regular le. -r le - True if le exists and is readable. -w le - True if le exists and is writable. -x le - True if le exists and is executable. -d le - True if le exists and is a directory. -s le - True if le exists and has a size greater than zero. String tests -nstr - True if string str is not a null string. -zstr - True if string str is a null string. str1 == str2 - True if both strings are equal. str - True if string str is assigned a value and is not null. str1!= str2 - True if both strings are unequal. -s le - True if le exists and has a size greater than zero. Test also permits the checking of more than one expression in the same line. -a - Performs the AND function -o - Performs the OR function The seq command- prints numeric sequences Syntax: seq [OPTION]... LAST seq[option]... FIRST LAST seq[option]... FIRST INCREMENT LAST The default separator character between each integer is a newline, but this can be changed with the -s option. bash$ seq bash$ seq -s : 5 1:2:3:4:5 More on the test command As we saw earlier, the test command is usually implemented using square bracket notation e.g. [ arguments ] 1
2 However there are some operators which may be used for special tests: $ [ -e lename ] && echo Filename exists The operator e examines the argument following and if that le exists, the command succeeds (exit status 0), or if it fails with an exit status 1. The following table lists the operators which may be used: -d lename True if the lename exists and is a directory -e lename True if the lename exists -f lename True if the lename exists and is regular -r lename True if the lename exists and is readable -s lename True if the lename exists and has size non-zero -w lename True if the lename exists and is writeable -x lename True if the lename exists and is executable A couple of rules about logical operators used as branches: If you write "test && command", the command will only be executed if the test succeeds. If you write "test command", the command will only be executed if the test fails. Try these tests: $ true&& echo "Yes." Yes. $ false echo "Yes." Yes. Notice that the outcomes are entirely in keeping with one's intuition about such logical comparisons, and all is well as long as you n't think about the fact that true equals 0. :) Here's another scheme commonly seen in shell script programming and interactive sessions: $ command1&& command2 && command3 && command4 This line of code will not run the next command in the sequence unless the prior command has returned "true", meaning no errors. It is a way to avoid running a command if a required prior outcome is not present. The if statement The general format for an if statement is: if [ condition is true ] execute these commands else execute those commands The else clause is optional, but you must end the construct with the command. You can also have nested if clauses by using the elif command like this: 2
3 Example if [ condition1 is true ] execute these commands elif [ condition2 is true ] execute these commands else execute those commands Here are some examples using the conditional expressions just listed. Note that the spaces on either side of the square brackets are not optional! if [ $price -gt ] else echo 'Too much.' echo 'Do you have one in blue?' For loops Examples For i in echo "Welcome $i times" For i in{1..5} echo "Welcome $i times" The next script lists a sequence between 1 and 20 in steps of 2,. For i in $(seq ) echo "Welcome $i times" The next script is similar the C programming construct for(( c=1; c<=5; c++)) echo "Welcome $c times..." The next script demonstrates an endless loop using the forloop. 3
4 for(( ; ; )) echo "innite loops [ hit CTRL+C to stop]" To perform an early exit with break statement inside the for loop or indeed a WHILE or UNTIL loop. The general break statement inside the for loop: for I in statements1#executed for all values of I, up to a disaster-condition if any. statements2 if(disaster-condition) break #Abann the loop. statements3#while good and, no disaster-condition. The following for loop will be abann when /etc/resolv.conf le found. for le in /etc/* if[ "${le}" == "/etc/resolv.conf" ] ; countnameservers=$(grep c nameserver/etc/resolv.conf) echo "Total ${countnameservers} nameservers dened in ${le}" break Brace Expansion Bash brace expansion is used to generate stings at the command line or in a shell script. The syntax for brace expansion consists of either a sequence specication or a comma separated list of items inside curly braces "{}". A sequence consists of a starting and ending item separated by two periods "..". Some examples and what they expand to: {aa,bb,cc,dd} =>aa bb cc dd {0..12} => {3..-2} => {a..g} =>a b c d e f g {g..a} =>g f e d c b a If the brace expansion has a prex or sufx string those strings are included in the expansion: a{0..3}b => a0b a1b a2b a3b Brace expansions can be nested: {a,b{1..3},c} => a b1 b2 b3 c 4
5 A counted for loop using brace expansion requires the least amount of typing: For i in {0..19} echo $i Using brace expansion is the only way to create a loop with non-numeric "indexes": For i in {a..z} echo $i Brace expansion can also be useful when passing multiple long pathnames to a command. Instead of typing: $rm /a/long/path/foo /a/long/path/bar You can simply type: $ rm /a/long/path/{foo,bar} Continuation with continue statement To resume the next iteration of the enclosing FOR, WHILE or UNTIL loop use continue statement. for I in statements1#executed for all values of ''I'', tildisaster-condition if any. statements2 if(condition) continue#next iteration of I in the loop and skip statements3 statements3 While Loops x=1 while[ $x -le 5 ] echo "Welcome $x times" x=$(( $x + 1 )) Until Loops Similar to thewhile is until; the syntax is the same but instead of the condition needing to succeed for the loop to continue, the condition must fail for the loop to nish and will give a non- zero exit status. 5
6 COUNT=0 # bash until loop until [ $COUNT -gt 5 ]; echo Value of count is: $COUNT let COUNT=COUNT+1 The case Statement Bash provides a case statement that lets you compare a string with several possible values and execute a block of code when it nds a match. Below is the general format: case "$var" in value1) commands;; value2) commands;; *)commands;; esac Where * indicates any string of characters Example echo "What is your preferred programming / scripting language" echo "1) bash" echo "2) perl" echo "3) phyton" echo "4) c++" echo "5) I not know!" read language; #simple case bash structure case $language in 1) echo "You selected bash";; 2) echo "You selected perl";; 3) echo "You selected phyton";; 4) echo "You selected c++";; 5) exit esac echo Enter A, B or C read letter case $letter in A a)echo You entered A ;; B b)echo You entered B ;; C c)echo You entered C ;; *) echo You didn\ t enter A, B or C ;; esac Where A a means either upper OR lower case A. echo "Please talk to me..." while : 6
7 read INPUT_STRING case$input_string in hello)echo "Hello yourself!;; bye)echo "See you again!"break;; *)echo "Sorry, I n't understand";; esac echo echo "That's all folks!" Functions Functions are similar to subroutines and procedures in other programming languages. The main difference between a script and a function is that a new instance of the shell is started for a shell script, whereas functions run in the current instance of the shell. Functions are dened as follows: name () { list ; } Here, name is the name of the function and list is a list of commands. The list of commands, list, is referred to as the body of the function. The parentheses, ( and), that follow name are required. function hello { echo Hello! } You can call function by typing its name: A function may return a value in three ways: Change the state of a variable or variables Use the exit command to end the shell script Use the return command to end the function, and return the supplied value to the calling section of the shell script This is rather like C, in that exit stops the program, and return returns control to the caller. The difference is that a shell function cannot change its parameters, though it can change global parameters. #!/bin/sh myfunc() { echo "I was called as : $@" x=2 } 7
8 ### Main script starts here echo "Script was called with x=1 echo "x is $x" myfunc echo "x is $x" The script, when called as scope.sh a b c, gives the following output: Aliases Script was called with a b c x is 1 I was called as : x is 2 Functions are general purpose and can be quite long. A Similar mechanism to replace short command sequences is aliases: $ alias ll= ls l more To remove an alias type unalias ll. Using bc as a calculator The bc utility is a programmable calculator. It allows several types of calculations and provides simple looping logic. It is also much easier to read than the expr expression evaluator. To start bc, type bc at the command line. Once bc begins, you are using calculator until you type quit. Try the following example. $ bc quit $ Using variables in bc Some versions of bc allow only single character variables, though later versions allow multi-character variable names. Notice that the assignments not result in any output from bc, it requires you to type an expression or variable without an assignment for it to be output to the screen. $ bc a=4 b=5 c=b-a c 1 quit $ The t variable holds the last output. In the following example the user enters 4+2 and bc outputs 6. Then the user enters. (t) and bc outputs 6, the value held in the temporary variable, again. The variable can itself be 8
9 used in an expression as in.+1, and bc outputs 7. Finally typing. (t) will again output 7 because the last output value, 7, has been assigned to. (t). $ bc quit $ Using bc in shell scripts To use bc in shell scripts just write a string with echo and pipe it into the input of bc. To add two floating point numbers say 2.5 and 3.75, type the string in quotes pipe it into the input of bc : echo " " bc 6.25 The same can be for subtraction, division and multiplication. The scale variable determines the number of digits which follow the decimal point in your result. By default, the value of the scale variable is zero. This can be set by declaring scale before your calculation, as in the following division example: $ echo scale=25;57/43 bc Square roots $ echo scale=30;sqrt(2) bc Powers $ echo 6^6 bc The use of brackets If you try to calculate this: $ echo 6^6^6 bc You will either get a screen full of numbers or an error message. You need to type: $ echo (6^6)^6 bc Whereas what you did type was interpreted as: $ echo 6^(6^6) bc 9
10 Example shell script echo "Enter a floating point number: " read a echo "Enter another floating point number: " read b echo "Addition: " echo "$a+$b" bc Exercises. 1. Write a script to prompt the user for two numbers, representing width and height of a rectangle in cm, and display the area of the rectangle both in square metres and in square inches ( 1 inch = 2.54 cm). Name this script "area.sh" 2. Create a bash shell script that reads in a number from the user. If the number is 1, print out the date. If the number is 2, list the les in the current directory. If the number is 3, print out who is currently logged onto the system. If the number is anything else, print out an error message and exit. Name this script "various.sh" 3. Create a bash shell script that reads any number of words from the command line and prints them out in reverse order. e.g. if your program is called reverse.sh you would type: brian$> reverse.sh Fred Ben Chris Mary Mustafa and it displays Mustafa Mary Chris Ben Fred Name this script "reverse.sh" 4. Develop a Unix shell script to input number of hours worked and pay rate and calculate the total pay, the social security amount (assume 5%), the net pay. Do this as a loop until the user enters zero for the number of hours worked (zero indicates that the program is to be terminated). 5. Write a Linux Bash shell script to compute the bonus for a salesperson as per the given pseucode. Convert the following pseucode into a Bash script: Read SalesPerson and QuarterlySales from the keyboard. Display an appropriate message regarding the bonus when the QuarterlySales for the SalesPerson falls within these ranges: 1,000,000 and above. Bonus = 1, ,000 to 999,999. Bonus = ,999 and below : No Bonus Test the script with the following data: Narinder Bob Mohamed Lisa Sarah Mary
11 6. Write a shell script to create a le with write permissions to members in your group and others but at a specied time input by the owner (using the at command), removes the write permissions from all except the owner of the le and sends a message to stut stating that the le has closed. 7. One type of lottery involves picking six different numbers, in the range of Write a script that generates six pseuranm numbers in this range, with no duplicates. The user will be prompted to input six numbers and the script will output the numbers of correct matches. The script will give the option of echoing the results to stut or saving them to a le, along with the date and time the player entered the nal number. All the programme should be clearly commented as outlined in the hanut marked How to cument shell scripts. The programs should contain comprehensive error checking where appropriate and screen dumps of the programs outputs including tests showing the outputs of all scenarios. e.g outputs when incorrect data is entered by the user. The highest grades will require the programs to be well written. This means the inclusion of functions, meaningful variable names, indentation etc. 11
Bash shell programming Part II Control statements
Bash shell programming Part II Control statements Deniz Savas and Michael Griffiths 2005-2011 Corporate Information and Computing Services The University of Sheffield Email M.Griffiths@sheffield.ac.uk
More informationUnix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, 2008. 1 Introduction 1. 2 Invoking Shell Scripts 2
Unix Shell Scripts Norman Matloff July 30, 2008 Contents 1 Introduction 1 2 Invoking Shell Scripts 2 2.1 Direct Interpretation....................................... 2 2.2 Indirect Interpretation......................................
More informationBASH Scripting. A bash script may consist of nothing but a series of command lines, e.g. The following helloworld.sh script simply does an echo.
BASH Scripting bash is great for simple scripts that automate things you would otherwise by typing on the command line. Your command line skills will carry over to bash scripting and vice versa. bash comments
More informationShell Scripts (1) For example: #!/bin/sh If they do not, the user's current shell will be used. Any Unix command can go in a shell script
Shell Programming Shell Scripts (1) Basically, a shell script is a text file with Unix commands in it. Shell scripts usually begin with a #! and a shell name For example: #!/bin/sh If they do not, the
More informationLecture 4: Writing shell scripts
Handout 5 06/03/03 1 Your rst shell script Lecture 4: Writing shell scripts Shell scripts are nothing other than les that contain shell commands that are run when you type the le at the command line. That
More informationUnix Scripts and Job Scheduling
Unix Scripts and Job Scheduling Michael B. Spring Department of Information Science and Telecommunications University of Pittsburgh spring@imap.pitt.edu http://www.sis.pitt.edu/~spring Overview Shell Scripts
More informationAnswers to Even-numbered Exercises
11 Answers to Even-numbered Exercises 1. 2. The special parameter "$@" is referenced twice in the out script (page 442). Explain what would be different if the parameter "$* " were used in its place. If
More informationAdvanced Bash Scripting. Joshua Malone (jmalone@ubergeeks.com)
Advanced Bash Scripting Joshua Malone (jmalone@ubergeeks.com) Why script in bash? You re probably already using it Great at managing external programs Powerful scripting language Portable and version-stable
More informationIntroduction to Shell Scripting
Introduction to Shell Scripting Lecture 1. Shell scripts are small programs. They let you automate multi-step processes, and give you the capability to use decision-making logic and repetitive loops. 2.
More informationPYTHON Basics http://hetland.org/writing/instant-hacking.html
CWCS Workshop May 2009 PYTHON Basics http://hetland.org/writing/instant-hacking.html Python is an easy to learn, modern, interpreted, object-oriented programming language. It was designed to be as simple
More informationLecture 2 Notes: Flow of Control
6.096 Introduction to C++ January, 2011 Massachusetts Institute of Technology John Marrero Lecture 2 Notes: Flow of Control 1 Motivation Normally, a program executes statements from first to last. The
More information9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements
9 Control Statements 9.1 Introduction The normal flow of execution in a high level language is sequential, i.e., each statement is executed in the order of its appearance in the program. However, depending
More informationSystems Programming & Scripting
Systems Programming & Scripting Lecture 14 - Shell Scripting: Control Structures, Functions Syst Prog & Scripting - Heriot Watt University 1 Control Structures Shell scripting supports creating more complex
More informationExercise 4 Learning Python language fundamentals
Exercise 4 Learning Python language fundamentals Work with numbers Python can be used as a powerful calculator. Practicing math calculations in Python will help you not only perform these tasks, but also
More informationCS2043 - Unix Tools & Scripting Lecture 9 Shell Scripting
CS2043 - Unix Tools & Scripting Lecture 9 Shell Scripting Spring 2015 1 February 9, 2015 1 based on slides by Hussam Abu-Libdeh, Bruno Abrahao and David Slater over the years Announcements Coursework adjustments
More informationWe will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.
LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.
More informationHands-On UNIX Exercise:
Hands-On UNIX Exercise: This exercise takes you around some of the features of the shell. Even if you don't need to use them all straight away, it's very useful to be aware of them and to know how to deal
More informationExample of a Java program
Example of a Java program class SomeNumbers static int square (int x) return x*x; public static void main (String[] args) int n=20; if (args.length > 0) // change default n = Integer.parseInt(args[0]);
More informationInformatica e Sistemi in Tempo Reale
Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)
More informationVisual Logic Instructions and Assignments
Visual Logic Instructions and Assignments Visual Logic can be installed from the CD that accompanies our textbook. It is a nifty tool for creating program flowcharts, but that is only half of the story.
More informationPython Lists and Loops
WEEK THREE Python Lists and Loops You ve made it to Week 3, well done! Most programs need to keep track of a list (or collection) of things (e.g. names) at one time or another, and this week we ll show
More informationJavaScript: Control Statements I
1 7 JavaScript: Control Statements I 7.1 Introduction 2 The techniques you will learn here are applicable to most high-level languages, including JavaScript 1 7.2 Algorithms 3 Any computable problem can
More informationF ahrenheit = 9 Celsius + 32
Problem 1 Write a complete C++ program that does the following. 1. It asks the user to enter a temperature in degrees celsius. 2. If the temperature is greater than 40, the program should once ask the
More informationBasic C Shell. helpdesk@stat.rice.edu. 11th August 2003
Basic C Shell helpdesk@stat.rice.edu 11th August 2003 This is a very brief guide to how to use cshell to speed up your use of Unix commands. Googling C Shell Tutorial can lead you to more detailed information.
More informationEventia Log Parsing Editor 1.0 Administration Guide
Eventia Log Parsing Editor 1.0 Administration Guide Revised: November 28, 2007 In This Document Overview page 2 Installation and Supported Platforms page 4 Menus and Main Window page 5 Creating Parsing
More informationHP-UX Essentials and Shell Programming Course Summary
Contact Us: (616) 875-4060 HP-UX Essentials and Shell Programming Course Summary Length: 5 Days Prerequisite: Basic computer skills Recommendation Statement: Student should be able to use a computer monitor,
More informationgrep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print
grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print In the simplest terms, grep (global regular expression print) will search input
More informationPHP Tutorial From beginner to master
PHP Tutorial From beginner to master PHP is a powerful tool for making dynamic and interactive Web pages. PHP is the widely-used, free, and efficient alternative to competitors such as Microsoft's ASP.
More informationJavaScript: Introduction to Scripting. 2008 Pearson Education, Inc. All rights reserved.
1 6 JavaScript: Introduction to Scripting 2 Comment is free, but facts are sacred. C. P. Scott The creditor hath a better memory than the debtor. James Howell When faced with a decision, I always ask,
More informationChapter 5 Programming Statements. Chapter Table of Contents
Chapter 5 Programming Statements Chapter Table of Contents OVERVIEW... 57 IF-THEN/ELSE STATEMENTS... 57 DO GROUPS... 58 IterativeExecution... 59 JUMPING... 61 MODULES... 62 Defining and Executing a Module....
More informationKeywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void
1. Explain C tokens Tokens are basic building blocks of a C program. A token is the smallest element of a C program that is meaningful to the compiler. The C compiler recognizes the following kinds of
More information6. Control Structures
- 35 - Control Structures: 6. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may bifurcate, repeat code or take decisions. For that purpose,
More informationA Crash Course on UNIX
A Crash Course on UNIX UNIX is an "operating system". Interface between user and data stored on computer. A Windows-style interface is not required. Many flavors of UNIX (and windows interfaces). Solaris,
More informationPerl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl
First CGI Script and Perl Perl in a nutshell Prof. Rasley shebang line tells the operating system where the Perl interpreter is located necessary on UNIX comment line ignored by the Perl interpreter End
More informationName: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.
Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to
More informationESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 6 Program Control
ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 6 Program Control Reading: Bowman, Chapters 16 CODE BLOCKS A code block consists of several lines of code contained between a BEGIN
More informationExercise 1: Python Language Basics
Exercise 1: Python Language Basics In this exercise we will cover the basic principles of the Python language. All languages have a standard set of functionality including the ability to comment code,
More informationVISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0
VISUAL GUIDE to RX Scripting for Roulette Xtreme - System Designer 2.0 UX Software - 2009 TABLE OF CONTENTS INTRODUCTION... ii What is this book about?... iii How to use this book... iii Time to start...
More informationUnix Shell Scripting Tutorial Ashley J.S Mills
Ashley J.S Mills Copyright 2005 The University Of Birmingham Table of Contents 1.Introduction... 1 2.Environment... 1 3. Shell Scripting... 1 3.1. Shell Scripting Introduction...
More informationPseudo code Tutorial and Exercises Teacher s Version
Pseudo code Tutorial and Exercises Teacher s Version Pseudo-code is an informal way to express the design of a computer program or an algorithm in 1.45. The aim is to get the idea quickly and also easy
More information3.GETTING STARTED WITH ORACLE8i
Oracle For Beginners Page : 1 3.GETTING STARTED WITH ORACLE8i Creating a table Datatypes Displaying table definition using DESCRIBE Inserting rows into a table Selecting rows from a table Editing SQL buffer
More informationChapter 8 Selection 8-1
Chapter 8 Selection 8-1 Selection (Decision) The second control logic structure is selection: Selection Choosing between two or more alternative actions. Selection statements alter the sequential flow
More informationIntroduction to Python
Caltech/LEAD Summer 2012 Computer Science Lecture 2: July 10, 2012 Introduction to Python The Python shell Outline Python as a calculator Arithmetic expressions Operator precedence Variables and assignment
More informationPython Loops and String Manipulation
WEEK TWO Python Loops and String Manipulation Last week, we showed you some basic Python programming and gave you some intriguing problems to solve. But it is hard to do anything really exciting until
More informationRetrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved.
Retrieving Data Using the SQL SELECT Statement Objectives After completing this lesson, you should be able to do the following: List the capabilities of SQL SELECT statements Execute a basic SELECT statement
More informationJ a v a Quiz (Unit 3, Test 0 Practice)
Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points
More informationIntroduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.
1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays
More informationIntroduction to Shell Programming
Introduction to Shell Programming what is shell programming? about cygwin review of basic UNIX TM pipelines of commands about shell scripts some new commands variables parameters and shift command substitution
More informationCommand Line - Part 1
Command Line - Part 1 STAT 133 Gaston Sanchez Department of Statistics, UC Berkeley gastonsanchez.com github.com/gastonstat Course web: gastonsanchez.com/teaching/stat133 GUIs 2 Graphical User Interfaces
More informationLab 1: Introduction to C, ASCII ART and the Linux Command Line Environment
.i.-' `-. i..' `/ \' _`.,-../ o o \.' ` ( / \ ) \\\ (_.'.'"`.`._) /// \\`._(..: :..)_.'// \`. \.:-:. /.'/ `-i-->..
More informationWriting Control Structures
Writing Control Structures Copyright 2006, Oracle. All rights reserved. Oracle Database 10g: PL/SQL Fundamentals 5-1 Objectives After completing this lesson, you should be able to do the following: Identify
More informationBASH scripting. Sebastian von Alfthan Scripting techniques 25.10.2010. CSC Tieteen tietotekniikan keskus Oy CSC IT Center for Science Ltd.
BASH scripting Sebastian von Alfthan Scripting techniques 25.10.2010 CSC Tieteen tietotekniikan keskus Oy CSC IT Center for Science Ltd. Introduction Shell scripting is the art of writing scripts that
More informationMATLAB Programming. Problem 1: Sequential
Division of Engineering Fundamentals, Copyright 1999 by J.C. Malzahn Kampe 1 / 21 MATLAB Programming When we use the phrase computer solution, it should be understood that a computer will only follow directions;
More informationLecture 22 The Shell and Shell Scripting
Lecture 22 The Shell and Shell Scripting In this lecture The UNIX shell Simple Shell Scripts Shell variables File System s, IO s, IO redirection Command Line Arguments Evaluating Expr in Shell Predicates,
More informationInstall Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html
CS 259: Data Structures with Java Hello World with the IntelliJ IDE Instructor: Joel Castellanos e-mail: joel.unm.edu Web: http://cs.unm.edu/~joel/ Office: Farris Engineering Center 319 8/19/2015 Install
More informationIntroduction to Python
WEEK ONE Introduction to Python Python is such a simple language to learn that we can throw away the manual and start with an example. Traditionally, the first program to write in any programming language
More informationSFTP SHELL SCRIPT USER GUIDE
SFTP SHELL SCRIPT USER GUIDE FCA US INFORMATION & COMMUNICATION TECHNOLOGY MANAGEMENT Overview The EBMX SFTP shell scripts provide a parameter driven workflow to place les on the EBMX servers and queue
More informationCSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals
CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals 1 Recall From Last Time: Java Program import java.util.scanner; public class EggBasket { public static void main(string[]
More informationWhat is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...
What is a Loop? CSC Intermediate Programming Looping A loop is a repetition control structure It causes a single statement or a group of statements to be executed repeatedly It uses a condition to control
More informationCS 241 Data Organization Coding Standards
CS 241 Data Organization Coding Standards Brooke Chenoweth University of New Mexico Spring 2016 CS-241 Coding Standards All projects and labs must follow the great and hallowed CS-241 coding standards.
More informationProgramming Exercises
s CMPS 5P (Professor Theresa Migler-VonDollen ): Assignment #8 Problem 6 Problem 1 Programming Exercises Modify the recursive Fibonacci program given in the chapter so that it prints tracing information.
More informationCS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013
Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)
More informationStacks. Linear data structures
Stacks Linear data structures Collection of components that can be arranged as a straight line Data structure grows or shrinks as we add or remove objects ADTs provide an abstract layer for various operations
More information5 Arrays and Pointers
5 Arrays and Pointers 5.1 One-dimensional arrays Arrays offer a convenient way to store and access blocks of data. Think of arrays as a sequential list that offers indexed access. For example, a list of
More informationPL / SQL Basics. Chapter 3
PL / SQL Basics Chapter 3 PL / SQL Basics PL / SQL block Lexical units Variable declarations PL / SQL types Expressions and operators PL / SQL control structures PL / SQL style guide 2 PL / SQL Block Basic
More informationChapter One Introduction to Programming
Chapter One Introduction to Programming 1-1 Algorithm and Flowchart Algorithm is a step-by-step procedure for calculation. More precisely, algorithm is an effective method expressed as a finite list of
More informationSelection Statements
Chapter 5 Selection Statements 1 Statements So far, we ve used return statements and expression ess statements. e ts. Most of C s remaining statements fall into three categories: Selection statements:
More informationWriting Shell Scripts in UNIX. A simple Bash-shell script. Comments and Commands
Writing Shell Scripts in UNIX Combining sets of commands into one file, which then may be run to execute the other commands. This is extremely useful for backups, moving files, general housekeeping. A
More informationBachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)
Unit- I Introduction to c Language: C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating
More informationAN INTRODUCTION TO UNIX
AN INTRODUCTION TO UNIX Paul Johnson School of Mathematics September 24, 2010 OUTLINE 1 SHELL SCRIPTS Shells 2 COMMAND LINE Command Line Input/Output 3 JOBS Processes Job Control 4 NETWORKING Working From
More informationCS2720 Practical Software Development
Page 1 Rex Forsyth CS2720 Practical Software Development CS2720 Practical Software Development Scripting Tutorial Srping 2011 Instructor: Rex Forsyth Office: C-558 E-mail: forsyth@cs.uleth.ca Tel: 329-2496
More information5.2 Q2 The control variable of a counter-controlled loop should be declared as: a.int. b.float. c.double. d.any of the above. ANS: a. int.
Java How to Program, 5/e Test Item File 1 of 5 Chapter 5 Section 5.2 5.2 Q1 Counter-controlled repetition requires a.a control variable and initial value. b.a control variable increment (or decrement).
More informationComputer Science 217
Computer Science 217 Midterm Exam Fall 2009 October 29, 2009 Name: ID: Instructions: Neatly print your name and ID number in the spaces provided above. Pick the best answer for each multiple choice question.
More informationEmbedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C
Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection
More informationALGORITHMS AND FLOWCHARTS. By Miss Reham Tufail
ALGORITHMS AND FLOWCHARTS By Miss Reham Tufail ALGORITHMS AND FLOWCHARTS A typical programming task can be divided into two phases: Problem solving phase produce an ordered sequence of steps that describe
More informationCLC Server Command Line Tools USER MANUAL
CLC Server Command Line Tools USER MANUAL Manual for CLC Server Command Line Tools 2.5 Windows, Mac OS X and Linux September 4, 2015 This software is for research purposes only. QIAGEN Aarhus A/S Silkeborgvej
More informationLinux Shell Script To Monitor Ftp Server Connection
Linux Shell Script To Monitor Ftp Server Connection Main goal of this script is to monitor ftp server. This script is example of how to use ftp command in bash shell. System administrator can use this
More informationTranslating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language
Translation Translating to Java Introduction to Computer Programming The job of a programmer is to translate a problem description into a computer language. You need to be able to convert a problem description
More informationMULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.
Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java
More informationALGORITHMS AND FLOWCHARTS
ALGORITHMS AND FLOWCHARTS A typical programming task can be divided into two phases: Problem solving phase produce an ordered sequence of steps that describe solution of problem this sequence of steps
More informationComputational Mathematics with Python
Computational Mathematics with Python Basics Claus Führer, Jan Erik Solem, Olivier Verdier Spring 2010 Claus Führer, Jan Erik Solem, Olivier Verdier Computational Mathematics with Python Spring 2010 1
More informationTwo-way selection. Branching and Looping
Control Structures: are those statements that decide the order in which individual statements or instructions of a program are executed or evaluated. Control Structures are broadly classified into: 1.
More informationComputational Mathematics with Python
Boolean Arrays Classes Computational Mathematics with Python Basics Olivier Verdier and Claus Führer 2009-03-24 Olivier Verdier and Claus Führer Computational Mathematics with Python 2009-03-24 1 / 40
More informationIntroduction to Java
Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high
More informationWelcome to Introduction to programming in Python
Welcome to Introduction to programming in Python Suffolk One, Ipswich, 4:30 to 6:00 Tuesday Jan 14, Jan 21, Jan 28, Feb 11 Welcome Fire exits Toilets Refreshments 1 Learning objectives of the course An
More informationComputers. An Introduction to Programming with Python. Programming Languages. Programs and Programming. CCHSG Visit June 2014. Dr.-Ing.
Computers An Introduction to Programming with Python CCHSG Visit June 2014 Dr.-Ing. Norbert Völker Many computing devices are embedded Can you think of computers/ computing devices you may have in your
More informationESPResSo Summer School 2012
ESPResSo Summer School 2012 Introduction to Tcl Pedro A. Sánchez Institute for Computational Physics Allmandring 3 D-70569 Stuttgart Germany http://www.icp.uni-stuttgart.de 2/26 Outline History, Characteristics,
More informationUniversity of Hull Department of Computer Science. Wrestling with Python Week 01 Playing with Python
Introduction Welcome to our Python sessions. University of Hull Department of Computer Science Wrestling with Python Week 01 Playing with Python Vsn. 1.0 Rob Miles 2013 Please follow the instructions carefully.
More informationThe C++ Language. Loops. ! Recall that a loop is another of the four basic programming language structures
The C++ Language Loops Loops! Recall that a loop is another of the four basic programming language structures Repeat statements until some condition is false. Condition False True Statement1 2 1 Loops
More informationConditions & Boolean Expressions
Conditions & Boolean Expressions 1 In C++, in order to ask a question, a program makes an assertion which is evaluated to either true (nonzero) or false (zero) by the computer at run time. Example: In
More informationTIP: To access the WinRunner help system at any time, press the F1 key.
CHAPTER 11 TEST SCRIPT LANGUAGE We will now look at the TSL language. You have already been exposed to this language at various points of this book. All the recorded scripts that WinRunner creates when
More informationFile class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)
File class in Java File Input and Output (Savitch, Chapter 10) TOPICS File Input Exception Handling File Output Programmers refer to input/output as "I/O". The File class represents files as objects. The
More informationMoving from CS 61A Scheme to CS 61B Java
Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you
More informationLab 4.4 Secret Messages: Indexing, Arrays, and Iteration
Lab 4.4 Secret Messages: Indexing, Arrays, and Iteration This JavaScript lab (the last of the series) focuses on indexing, arrays, and iteration, but it also provides another context for practicing with
More informationProgramming Languages CIS 443
Course Objectives Programming Languages CIS 443 0.1 Lexical analysis Syntax Semantics Functional programming Variable lifetime and scoping Parameter passing Object-oriented programming Continuations Exception
More informationAutomating admin tasks using shell scripts and cron Vijay Kumar Adhikari. vijay@kcm
Automating admin tasks using shell scripts and cron Vijay Kumar Adhikari vijay@kcm kcm.edu.np How do we go? Introduction to shell scripts Example scripts Introduce concepts at we encounter them in examples
More informationThe Linux Operating System and Linux-Related Issues
Review Questions: The Linux Operating System and Linux-Related Issues 1. Explain what is meant by the term copyleft. 2. In what ways is the Linux operating system superior to the UNIX operating system
More informationUnit 1 Number Sense. In this unit, students will study repeating decimals, percents, fractions, decimals, and proportions.
Unit 1 Number Sense In this unit, students will study repeating decimals, percents, fractions, decimals, and proportions. BLM Three Types of Percent Problems (p L-34) is a summary BLM for the material
More informationPHP Debugging. Draft: March 19, 2013 2013 Christopher Vickery
PHP Debugging Draft: March 19, 2013 2013 Christopher Vickery Introduction Debugging is the art of locating errors in your code. There are three types of errors to deal with: 1. Syntax errors: When code
More informationawk A UNIX tool to manipulate and generate formatted data
awk A UNIX tool to manipulate and generate formatted data Alexander Voigt Technische Universität Dresden Institut für Kern- und Teilchenphysik Version_05_21 /01234/546 78994: IKTP Computing Kaffee 10 January
More information