Review.

Slides:



Advertisements
Similar presentations
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Advertisements

CS 497C – Introduction to UNIX Lecture 33: - Shell Programming Chin-Chih Chang
More Shell Basics CS465 - Unix. Unix shells User’s default shell - specified in /etc/passwd file To show which shell you are currently using: $ echo $SHELL.
T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015.
Bash Shell Scripting 10 Second Guide Common environment variables PATH - Sets the search path for any executable command. Similar to the PATH variable.
Introduction to Linux and Shell Scripting Jacob Chan.
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.
Shell Control Structures CSE 2031 Fall August 2015.
Agenda Control Flow Statements Purpose test statement if / elif / else Statements for loops while vs. until statements case statement break vs. continue.
1 Operating Systems Lecture 3 Shell Scripts. 2 Shell Programming 1.Shell scripts must be marked as executable: chmod a+x myScript 2. Use # to start a.
1 Operating Systems Lecture 3 Shell Scripts. 2 Brief review of unix1.txt n Glob Construct (metacharacters) and other special characters F ?, *, [] F Ex.
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.
Introduction to Linux OS (IV) AUBG ICoSCIS Team Prof. Volin Karagiozov March, 09 – 10, 2013 SWU, Blagoevgrad.
Linux+ Guide to Linux Certification, Third Edition
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 11: Shell.
Shell Programming. Introducing UNIX Shells  Shell is also a programming language and provides various features like variables, branching, looping and.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
Agenda Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Review next lab assignments Break Out Problems.
Chapter 10: BASH Shell Scripting Fun with fi. In this chapter … Control structures File descriptors Variables.
Lecture 24CS311 – Operating Systems 1 1 CS311 – Lecture 24 Outline Final Exam Study Guide Note: These lecture notes are not intended replace your notes.
UNIX An Introduction. Brief History UNIX UNIX Created at Bell Labs, 1969 Created at Bell Labs, 1969 BSD during mid 70s BSD during mid 70s AT&T began offering.
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.
Xuan Guo Chapter 5 The Bourne Shell Graham Glass and King Ables, UNIX for Programmers and Users, Third Edition, Pearson Prentice Hall, Notes by Michael.
1 Lecture 9 Shell Programming – Command substitution Regular expressions and grep Use of exit, for loop and expr commands COP 3353 Introduction to UNIX.
1 © 2000 John Urrutia. All rights reserved. Session 5 The Bourne Shell.
CS252: Systems Programming Ninghui Li Slides by Prof. Gustavo Rodriguez-Rivera Topic 7: Unix Tools and Shell Scripts.
Week Two Agenda Announcements Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Next lab assignments.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 2a – A Unix Command Sampler (Courtesy of David Notkin, CSE 303)
Shell Control Statements and More
Chapter 5 The Bourne Shell Graham Glass and King Ables, UNIX for Programmers and Users, Third Edition, Pearson Prentice Hall, Notes by Michael Weeks.
1 UNIX Operating Systems II Part 2: Shell Scripting Instructor: Stan Isaacs.
Shell Control Structures CSE 2031 Fall June 2016.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
Bash Shell Scripting 10 Second Guide.
Tutorial of Unix Command & shell scriptS 5027
User-Written Functions
Shell Control Structures
Agenda Bash Shell Scripting – Part II Logic statements Loop statements
Part 1: Basic Commands/Utilities
Some Linux Commands.
Shell Scripting March 1st, 2004 Class Meeting 7.
Lecture 9 Shell Programming – Command substitution
Shell Programming (ch 10)
Unix Scripting Session 4 March 27, 2008.
CSE 374 Programming Concepts & Tools
Tutorial of Unix Command & shell scriptS 5027
Tutorial of Unix Command & shell scriptS 5027
Agenda Control Flow Statements Purpose test statement
Pepper (Help from Dr. Robert Siegfried)
Fork and Exec Unix Model
CSC 352– Unix Programming, Spring 2016
Tutorial of Unix Command & shell scriptS 5027
UNIX Reference Sheets CSE 2031 Fall 2010.
CSC215 Lecture Control Flow.
Command Substitution Command substitution is the mechanism by which the shell performs a given set of commands and then substitutes their output in the.
Tutorial Unix Command & Makefile CIS 5027
CSE 303 Concepts and Tools for Software Development
Linux Shell Script Programming
CSE 303 Concepts and Tools for Software Development
Shell Control Structures
Chapter 5 The Bourne Shell
Shell Control Structures
Essential Shell Programming
Introduction to Bash Programming, part 3
CSC215 Lecture Control Flow.
Review The Unix Shells Graham Glass and King Ables,
Presentation transcript:

Review

UNIX Features Multiple users access a system at the same time Support file management and process management Provide a directory hierarchy Share CPUs, memory, and disk space Allow processes and peripherals to talk to each other Standard utilities System calls A portable operating system

Common UNIX utilities pwd cat , more, page, head, tail ls, cd mv, cp, rm mkdir, rmdir file, wc , lp vi groups, chgrp, chmod

Grep Filtering patterns: egrep, fgrep, grep grep -hilnvw pattern {fileName}* displays lines from files that match the pattern pattern : regular expression -h : do not list file names if many files are specified -i : ignore case -l : displays list of files containing pattern -n : display line numbers v : displays lines that do not match the pattern -w : matches only whole words only

Grep variations fgrep : pattern must be fixed string egrep : pattern can be extended regular expression -x option in fgrep: displays only lines that are exactly equal to string extended regular expressions: + matches one or more of the single preceding character ? matches zero or one of the single preceding character | either or (ex. a* | b*)‏ () *, +, ? operate on entire subexpression not just on preceding character; ex. (ab | ba)*

Sort sort -tc -r [+POS1 [-POS2]] {sortField -bfMn}* {fileName}* -tc separator is c instead of blank -r descending instead of ascending -b ignore leading blanks -f ignore case -M month sort (3 letter month abbreviation)‏ -n numeric sort +POS1 [-POS2] key positions start [up to end]

find Utility awk tar Utility Stream Editor (sed)

Environment Variables $HOME : full pathname of home directory $PATH : list of directories to search for commands $MAIL : the full pathname of mailbox $USER : your username $SHELL : the full pathname of login shell $TERM : the type of your terminal

Built-In Variables $$ the process ID of the shell $0 the name of the shell script $1..$9 $n refers to the nth command line argument $* a list of all command-line arguments

Test Command test expression [ expression ] (equivalent form on some UNIX: if it’s built-in) Returns a zero if expression evaluates to true Otherwise, returns a nonzero status. Examples: $ test 2 -eq 3; $ test -e for.sh; $ test abc = abc;

Case Structure case expression in pattern)‏ list ;; pattern2)‏ list2 ... *) # default list_n esac

Control Structures: for .. do .. done for name [in {word}* ] do list done Loops the value of name through each word in the word list, evaluates commands in the list at each iteration. If no word list is supplied, $@ is used. break : terminate the loop immediately. continue : jump to the next iteration.

Control Structures: if .. then .. fi if list1 then list2 elif list3 #may be repeated several times list4 else #may occur zero or one time list5 fi Commands in list1 are executed. If last command succeeds, the list2 is executed. Otherwise, a successful command list in elif causes the associated then to be executed.

Control Structures: until .. do .. done until list1 do list2 done Executes list1 If the last command in list1 succeeds, it ends. Otherwise, list2 is executed and the process is repeated. If list2 is empty, the do keyword should be omitted. break continue

Control Structures: while .. done while list1 do list2 done Executes list1. If the last command in list1 fails, it ends Otherwise, list2 is executed and the process is repeated. If list2 is empty, the do keyword should be omitted. break continue

C programming Operator precedence and associativity Pointers arithmetic Relationship between array and pointers Linked List operations

if … else Statement if (expression) statement if (expression) statement else statement Statement can be compound: { statements} if (i==0) vs if (i=0) if (expression) statement else if (expression) … else

Conditional Expression expr1 ? expr2: expr3 int i, j, k; i = 1; j = 2; k = i > j ? i : j ; k = (i > 0 ? i : 0) + j ; return (i > j ? i : j); printf (“%d\n”, i > j ? i : j);

switch Statement switch ( expression ){ case constant-expression: statements … default: statements } Controlling expression should be an integer expression (characters) Constant expression can’t contain variables or function calls. Statements do not require {}. Usually, the last statement is break.

while Loop while (expression) statement Statement can be compound: {} while (i>0) printf (“%d\n”, i--); while (i>0) { printf (“%d\n”, i); i--; } Infinite loops: while(1) Break, goto, return

do Loop do statement while (expression); Statement can be compound: {} do printf (“%d\n”, i--); while (i>0) ; do { printf (“%d\n”, i); i--; } while (i>0);

for Loop for (expr1; expr2; expr3) statement Statement can be compound: {} expr1; while (expr2) { statement expr3; } Infinite loop: for (;;) break statement continue statement

Functions return type function-name (parameters) { declarations statements } Function can not return array Pass-by-value Pass-by-reference

Declaring Structures (struct) Engineering H192 Winter 2005 Declaring Structures (struct) struct date { int day; char month[3]; char year[4]; } ; /* The name “date" is called a structure tag */ Struct date date1; Struct date date2 = {3,”Jan”,”1912”}; Struct { int day; char month[3]; char year[4]; } my_date ; my_date date3 = {2,”Jul”,”2010”}; Instructor: A structure can be defined in two ways. The first method gives the compiler the layout or structure of the struct, but does not actually create one for use. This is useful when the programmer wishes to create global definitions for structs that he or she wishes to use later. The second method varies only in that a variable name now exists after the closing brace of the structure. This variable is now a struct which contains all the variables within the struct definition. Accessing the data in this variable will be discussed in a few slides. Lecture 23

Compiling and Linking

Example of Makefile main1: main.o power.o cc power.o main.o -o main1 main.o: main.c power.h cc -c main.c power.o: power.c power.h cc -c power.c

Error Handling errno perror()

File Management open read/write lseek close Stat Fcntl chmod

Process Management fork()‏ getpid()‏ getppid()‏ exit()‏ wait()‏ exec()