2000 Copyrigths Danielle S. Lahmani UNIX Tools G22.2245-001, Fall 2000 Danielle S. Lahmani Lecture 4.

Slides:



Advertisements
Similar presentations
CIS 240 Introduction to UNIX Instructor: Sue Sampson.
Advertisements

CIS 118 – Intro to UNIX Shells 1. 2 What is a shell? Bourne shell – Developed by Steve Bourne at AT&T Korn shell – Developed by David Korn at AT&T C-shell.
CHAPTER 2 THE UNIX SHELLS by U ğ ur Halıcı. layers in a unix system 1 Users Standard utility programs (shell, editors, compilers, etc.) Standard utility.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
Chapter Seven Unix Shell Environments1 System Programming UNIX Shell Environments.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Linux+ Guide to Linux Certification, Second Edition
Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.
2000 Copyrigths Danielle S. Lahmani UNIX Tools G , Fall 2000 Danielle S. Lahmani Lecture 3.
23-Jun-15Advanced Programming Spring 2002 bash Henning Schulzrinne Department of Computer Science Columbia University.
CS 497C – Introduction to UNIX Lecture 36: - Customizing the Environment Chin-Chih Chang
2000 Copyrights Danielle S. Lahmani UNIX Tools G , Fall 2000 Danielle S. Lahmani Lecture 5.
The UNIX Shells 1. What is a Unix shell? 2. A few common shells in the Unix & Linux. A. Bourne shell B. Korn shell C. C shell D. Bash-the default shell.
Scripting Languages and C-Shell. What is a scripting language ? Script is a sequence of commands written as plain text and run by an interpreter (shell).
Guide To UNIX Using Linux Third Edition
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
Using Linux Commands 2 Lab#5
Shell Script Examples.
Using Linux Commands 2 Lab#5. Sort command Sort the lines of text files. $ sort fileName by default it will sort in normal order(alphabetical 0-9 A-Z.
Lecture 3  Shell Variables  Shell Command History  Job / Process Control  Directory Control.
Introduction to Shell Script Programming
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
Chapter 5 Bourne Shells Scripts By C. Shing ITEC Dept Radford University.
Chapter 6: Shell Programming
Unix Shells: C, Bourne, Bourne Again, Korn, and Tenex Shells Presentation by: Katie Harris Andrew Murray.
An Introduction to Unix Shell Scripting
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.
Shell Features CSCI N321 – System and Network Administration Copyright © 2000, 2005 by Scott Orr and the Trustees of Indiana University.
CS 2061 Shells Also known as: Unix Command Interpreter.
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.
Introduction to Unix – CS 21 Lecture 9. Lecture Overview Shell description Shell choices History Aliases Topic review.
Chapter 4 UNIX Common Shells Commands By C. Shing ITEC Dept Radford University.
1 UNIX essentials (hands-on) the directory tree running programs the shell → command line processing → special characters → command types → shell variables.
Shell Script Programming. 2 Using UNIX Shell Scripts Unlike high-level language programs, shell scripts do not have to be converted into machine language.
Additional UNIX Commands. 222 Lecture Overview  Multiple commands and job control  More useful UNIX utilities.
Introduction to Linux OS (IV) AUBG ICoSCIS Team Prof. Volin Karagiozov March, 09 – 10, 2013 SWU, Blagoevgrad.
LINUX System : Lecture 6 Shell Programming
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
CS465 - UNIX The Bourne Shell.
Beyond sh Not everyone is as fond of UNIX as most other people. The tutorial talks about the dark side of UNIX.
1 Operating Systems Lecture 2 UNIX and Shell Scripts.
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.
Customizing the Shell Environment. UNIX Shells Two characteristics of shells –Interactive: prompts ($) and waits for your response/requests –Noninteractive:
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
1 Unix/Linux commands and shell programming-Part 2 (Dr. Mohamed El Bachir Menai)
CSCI 330 UNIX and Network Programming Unit III Shell, Part 1.
Chapter 8: The Bourne Again Shell It’s a command interpreter, it’s a programming language, and it makes a mean martini.
Linux+ Guide to Linux Certification, Second Edition
Introduction to Bash Shell. What is Shell? The shell is a command interpreter. It is the layer between the operating system kernel and the user.
1 © 2012 John Urrutia. All rights reserved. Chapter 09 The TC Shell.
Lesson 8-Specifying Instructions to the Shell. Overview An overview of shell. Execution of commands in a shell. Shell command-line expansion. Customizing.
1 Lecture 7 Introduction to Shell Scripts COP 3353 Introduction to UNIX.
Linux Administration Working with the BASH Shell.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
CS 350 Lecture 3 UNIX/Linux Shells by İlker Korkmaz and Kaya Oğuz.
Lecture 7 Introduction to Shell Programming
SUSE Linux Enterprise Desktop Administration
Lecture 7 Introduction to Shell Scripts COP 3353 Introduction to UNIX.
Introduction to Shells
Shell Features CSCI N321 – System and Network Administration
The UNIX Shell Learning Objectives:
John Carelli, Instructor Kutztown University
Shell Programming.
Linux Shell Script Programming
CSE 303 Concepts and Tools for Software Development
Chapter 3 The UNIX Shells
Introduction to Bash Programming, part 3
Presentation transcript:

2000 Copyrigths Danielle S. Lahmani UNIX Tools G , Fall 2000 Danielle S. Lahmani Lecture 4

2000 Copyrigths Danielle S. Lahmani Overview shell core functionality /bin/sh /bin/ksh /bin/csh

2000 Copyrigths Danielle S. Lahmani Shell Core Features Simple and complex commands redirection of input/output pipes wildcards command substitution background processes shell variables here documents built-in cmds programming constructs

2000 Copyrigths Danielle S. Lahmani The Korn Shell: /bin/ksh Supports all features described in the Bourne shell (/bin/sh) Alias mechanism History mechanism for access of previous commands Functions Enhanced job control Arithmetic Tilde substitution

2000 Copyrigths Danielle S. Lahmani The Korn shell: /bin/ksh STARTUP FILES: –/etc/profile –$HOME/.profile ALIAS: –alias [-tx] [word[=string]] –alias -x : to export alias to child shell –unalias aliasname: to remove an alias

2000 Copyrigths Danielle S. Lahmani /bin/ksh: History Mechanism Numbered commands $ PS1='!!’ /* set prompt to contains a ! */ $HISTSIZE default is 128 using the built-in vi editor –declare VISUAL=vi or EDITOR=vi –to edit current line, press ESC key to enter the editor –vi cmds to edit line, when done, press ESC key again, –additional movement: cursor up (k or - ) cursor down (j or +) –additional searching /string or ?string : searches backward and forward through history, respectively.

2000 Copyrigths Danielle S. Lahmani /bin/ksh (continued) ARITHMETIC: Using let expression TILDE SUBSTITUTION –~$HOME –~userhome directory of user –~/pathname$HOME/pathname –~+$PWD –~-$OLDPWD

2000 Copyrigths Danielle S. Lahmani /bin/ksh: FUNCTIONS Allows functions that may be invoked as shell commands function name { list of commands } or name() { list of commands }

2000 Copyrigths Danielle S. Lahmani /bin/ksh: Functions (continued) can use parameters returning from a function local variable using typeset functions can be recursive

2000 Copyrigths Danielle S. Lahmani /bin/ksh: ENHANCED JOB CONTROL jobslist your jobs bgplaces a specified job in the background fgplaces a specified job in the foreground killsends an arbitrary signal to a process or job ^zto stop a foreground job stop to suspend a background job

2000 Copyrigths Danielle S. Lahmani /bin/ksh: coprocess PIPES |& operator supports a simple form of concurrent processing cmd |& cmd run as a background process whose standard input and output channels are connected to the original parent shell via a two way pipe.

2000 Copyrigths Danielle S. Lahmani The C Shell: /bin/csh Supports all features described in the Bourne shell simple and list variables Alias mechanism with arguments History mechanism for access of previous commands Enhanced job control Arithmetic directory stack

2000 Copyrigths Danielle S. Lahmani /bin/csh: STARTUP FILES $HOME/.cshrc /etc/.login $HOME/.login

2000 Copyrigths Danielle S. Lahmani /bin/csh: simple variables set { name [=word]} * access –$(name) –${name} –${?name}replaced by 1 if name is set, 0 otherwise

2000 Copyrigths Danielle S. Lahmani /bin/csh: list variables Variables to which you can assign a list of values set { name = ( {word}*) } * Access: $name[selector] ${name[selector]}selector can be a range $#name ${#name}number of elements in name

2000 Copyrigths Danielle S. Lahmani /bin/csh: predefined local variables $< the next line of standard input fully quoted $noclobberprevents existing files from being overridden by >, and non-existent files from being appended to by >> $noglobprevents wildcard expansion

2000 Copyrigths Danielle S. Lahmani /bin/csh: methods for accessing C shell arguments $argva list that contains all of the positional parameters, same as $* $argv[1]is equal to $1 $#argvnumber of arguments $argv[1-n] arguments 1 through n $argv[0] illegal, must use $0 $argv[$#argv] last argument

2000 Copyrigths Danielle S. Lahmani /bin/csh:file inquiry operator -option filename operatormeaning rread access wwrite access xexecute access eexistence oownership zzero length fplain file ddirectory

2000 Copyrigths Danielle S. Lahmani /bin/csh: ARITHMETIC EXPRESSION Assignment of results of an expression: Set variable to variable op variable[index] op expression x = %echo $x 5

2000 Copyrigths Danielle S. Lahmani /bin/csh:ALIAS alias [word[string]] unalias to share an alias with other subshells, place it under.cshrc

2000 Copyrigths Danielle S. Lahmani ARGUMENTS IN ALIASES C shell assumes that all arguments come at the end of the alias definition, unless you specify otherwise –Example % alias cx chmod +x –% cx * # makes files in all current directory executable –Two common arguments designations to pass arguments to aliases

2000 Copyrigths Danielle S. Lahmani /bin/csh alias example reference: The Unix C shell field Guide G, Anderson P. Anderson find requires a single argument, we must escape ! to suppress interpretation from the C shell %alias loc 'find ~ -name \!^ - print' %loc ttydoc77 % alias ldir 'ls -l \!* | grep "^d"' % ldir../utils /usr/bin

2000 Copyrigths Danielle S. Lahmani /bin/csh: history mechanism For numbered commands –set prompt = '\! %’ storage of commands –set history = 40size of history file –set savehist=32save 32 commands across sessions

2000 Copyrigths Danielle S. Lahmani /bin/csh: hist mech (continued) command reexecution –!!reexecute previous command –!number –!prefix –!?substring command editing –% !even :s/pat1/pat2 substitute pat1 with pat2 –%^pat1^pat2reexecution of previous command substituting pat1 with pat2

2000 Copyrigths Danielle S. Lahmani ACCESS PORTION OF A FILENAME Modifierpart of fileportion of filename returned :hheadfilename minus trailing path :rrootfilename minus trailing *.suffix :eextensiontrailing.* suffix :ttailfilename minus leading dir path

2000 Copyrigths Danielle S. Lahmani /bin/csh: CONTROL STRUCTURES foreach ……. end if then else endif switch case … endsw while … end onintr [-l label] allows to specify a label to jump to when shell receives a SIGINT

2000 Copyrigths Danielle S. Lahmani /bin/csh: PIPING Process1 |& process2 Redirects standard output and standard error from process 1 to process 2

2000 Copyrigths Danielle S. Lahmani /bin/csh:MULTIPLE REDIRECTION Cmd >& filesend both standard output and standard error to file Cmd >&! file same as above, even in noclobber is set Cmd >>& file append standard error and standard output to end of file Cmd1 | & cmd2 pipe standard error together with standard output (cmd > file1) >& file2 send standard output to file1; send standard error to file2

2000 Copyrigths Danielle S. Lahmani /bin/csh: JOB CONTROL Same as ksh, plus stopsuspend background process suspendsuspend foreground process notifynotify when current job changes status

2000 Copyrigths Danielle S. Lahmani /bin/csh: DIRECTORY STACK pushd [+number|name] pushd pushes the directory onto the directory stack popd [+number] popdpops a directory from the directory stack dirs: lists the current directory stack.

2000 Copyrigths Danielle S. Lahmani Effective and efficient shell prog reference: Unix shell Tutorial G.Snyder J.R. Mashey Bell Labs Minimize number of processes generated Find out which cmds are built-in and which are not.  Number of data bytes accessed  Minimize Directory searches  Optimize Directory search order and the PATH variable  Minimize arithmetic and character processing  Avoid command substitution when you can  Move loop invariant outside of loop, especially for command substitution