Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell The Shell The agency that.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process The Process A process is.
1 © 2001 John Urrutia. All rights reserved. Chapter 5 The Shell Overview.
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.
CS 497C – Introduction to UNIX Lecture 22: - The Shell Chin-Chih Chang
1 CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection slides created by Marty Stepp, modified by Josh Goodwin
Linux+ Guide to Linux Certification, Second Edition
Shell Basics CS465 - Unix. Shell Basics Shells provide: –Command interpretation –Multiple commands on a single line –Expansion of wildcard filenames –Redirection.
CS 497C – Introduction to UNIX Lecture 21: - The Shell Chin-Chih Chang
Linux+ Guide to Linux Certification, Second Edition
CS 497C – Introduction to UNIX Lecture 20: - The Shell Chin-Chih Chang
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.
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.
CS 497C – Introduction to UNIX Lecture 4: Understanding the UNIX Command Chin-Chih Chang
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Introduction to Linux and Shell Scripting Jacob Chan.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – Shell Programming The activities of.
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
3 File Processing Mauro Jaskelioff. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash.
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
File Processing. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash facilities.
Guide To UNIX Using Linux Fourth Edition
Shrinivas R. Mangalwede, GIT, Belgaum UNIX and Shell Programming (06CS36) Unit 3 Shrinivas R. Mangalwede Department of Computer Science and Engineering.
Unix Shells Based on Glass & Abels’ Book CS240 Computer Science II.
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.
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.
Chapter 4 UNIX Common Shells Commands By C. Shing ITEC Dept Radford University.
The Shell Chapter 7. Overview The Command Line Standard IO Redirection Pipes Running a Program in the Background Killing (a process!)
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. The Operating System Allocates memory for.
UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
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
LINUX programming 1. INDEX UNIT-III PPT SLIDES Srl. No. Module as per Session planner Lecture No. PPT Slide No. 1.Problem solving approaches in Unix,Using.
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
Module 6 – Redirections, Pipes and Power Tools.. STDin 0 STDout 1 STDerr 2 Redirections.
1 Operating Systems Lecture 2 UNIX and Shell Scripts.
Lesson 2 1.Commands 2.Filename Substitution 3.I/O Redirection 4.Command Grouping 5.Shell Responisibilites Review of the Basics.
Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will.
Lesson 2-Touring Essential Programs. Overview Development of UNIX and Linux. Commands to execute utilities. Communicating instructions to the shell. Navigating.
LINUX programming UNIT-2 1. INDEX UNIT-IV PPT SLIDES Srl. No. Module as per Session planner Lecture No. PPT Slide No. 1.Working with Bourne shell L1 1-2.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX Commands cal – will print a calendar.
Introduction to Programming Using C An Introduction to Operating Systems.
Week 9 - Nov 7, Week 9 Agenda I/O redirection I/O redirection pipe pipe tee tee.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
THE BOURNE SHELL. Shell : the agency that sits between the user and the UNIX system. The BOURNE SHELL named after its founder Steve Bourne, is one of.
Chapter 5: The Shell The Man in the Middle. In this chapter … The command line Input, output, and redirection Process management Wildcards and expansion.
Agenda The Bourne Shell – Part II Special Characters Ambiguous File Reference Variable Names and Values User Created Variables Read-only Variables (Positional.
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
Linux+ Guide to Linux Certification, Second Edition
© Prepared By: Razif Razali 1 TMK 265: UNIX SYSTEM CHAPTER FOUR – QUOTING IN DETAIL.
Agenda The Bourne Shell – Part I Redirection ( >, >>,
File Processing. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash facilities.
Lesson 8-Specifying Instructions to the Shell. Overview An overview of shell. Execution of commands in a shell. Shell command-line expansion. Customizing.
Linux Administration Working with the BASH Shell.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
Shells.
SUSE Linux Enterprise Desktop Administration
Shell Features CSCI N321 – System and Network Administration
System Programming and administration CS 308
Introduction Paul Flynn
Linux Shell Script Programming
UNIX and Shell Programming (06CS36)
Chapter 3 The UNIX Shells
CSC 4630 Meeting 4 January 29, 2007.
Presentation transcript:

second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell The Shell The agency that sits between the user and the UNIX system All the wonderful things that we can do with UNIX are possible because the Shell does a lot of work on our behalf Shell looks for special symbols in the command line, perform the tasks associated with them, and then executes the command. for example, it opens a file to save command ouput whenever it sees the > symbol.

second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell The Shell Unique and Multifaceted program It is a command interpreter and a programming language rolled into one It is a process that creates an environment to work in focus is on the shell’s basic interpretive activities rm * or ls | more

second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell The Shell as a Command Processor When you login to a UNIX machine, you first see a prompt A UNIX command starts running at the terminal when you login It starts functioning when we log in It withers away when we log out This command is the UNIX shell run the ps command (shows processes); you will see it running; $ ps

second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell The Shell as a Command Processor When we key in a command, it goes as input to the shell The shell first scans the command line for metacharacters Metacharacters are special characters that mean nothing to the command, but means something special to the shell echo date > date.sh rm * ls | more

second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell The Shell as a Command Processor When the shell sees the metacharacters like the >, |, *, etc. in its input, it translates these symbols to their respective actions before the command is executed. It replaces the * with all filenames in the current directory so that rm ultimately runs with these names as arguments. When the shell sees >, it opens the file date.sh and connects echo’s output to it

second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell The Shell as a Command Processor Basically the shell recreates the command line by removing all metacharacters and finally passes on the command to the kernel for execution

second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell The Shell as a Command Processor Following activities are typically performed Shell issues a prompt and waits for you to enter a command It scans the command line for metacharacters and expands abbreviations to create a simplified command line It then passes on the command line to the kernel for execution The shell waits for the command to complete and normally can’t do any work while the command is running After the command execution is complete, the prompt reappears and the shell returns to its waiting role to start the next cycle.

second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell Shell offerings UNIX system offers a variety of shells for you to choose from. The shells we consider can be grouped into two categories: The Bourne family comprising the Bourne shell (/bin/sh) and its derivatives – the Korn shell (/bin/ksh) and Bash (/bin/bash) The C Shell (/bin/csh) and its derivatives, Tcsh (/bin/tcsh) To know the shell you are using invoke $SHELL

second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell Pattern Matching – The Wild Cards The * and ? The * metacharacter is one of the characters of the shell’s special set. It matches any number of characters including none. When it is appended to the string chap, the chap* matches filenames beginning with the string chap – including the file chap ls -l chap* echo * rm * -- bad news

second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell Pattern Matching – The Wild Cards The * and ? The ? Matches a single character. ls chap? chapx chapy chapz ls chap?? chap01 chap02 chap03 chap04 chap15 chap16 chap17

second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell Pattern Matching – The Wild Cards The Character Class It comprise a set of characters enclosed by the brackets [ and ], but it matches a single character in the class ls chap0[124] chap01 chap02 chap04 ls chap0[1-4] range 1,2,3,4 ls chap[x-z]

second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell Pattern Matching – The Wild Cards The Mystery of the find Command find / -name “*.[hH][tT][mM][lL]” –print will display html and HTML files find. –name “note??” –print wild cards in the feature of find and not the shell quotes around the pattern, ensures that the shell can’t even interpret this pattern.

second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell Pattern Matching – The Wild Cards Matching the Dot The * and ? Don’t match all filenames beginning with a. (dot) to matche hidden files in your directory having at least 3 characters after the dot, ls.???* to match files with the dot anywhere but the beginning ls *c

second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell Redirection What is a Terminal? a generic name that represents the screen, display or keyboard (or even an X window that emulates a terminal) We see command output and error messages on the terminal (display), and we sometimes provide command input through the terminal (keyboard) The shell associates three files with the terminal two for display and one for keyboard

second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell Redirection What is a Terminal? even though our terminal is also represented by a specific device name, commands don’t usually read from or write to this file. All terminal related activity is performed with the three files that the shell makes available to every command These files are actually streams of characters which many commands see as input and ouput

second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell Redirection What is a Terminal? stream is simply a sequence of bytes when a user logs in, shell makes available 3 files representing three streams each stream is associated with a default device, and generally speaking the device is the terminal

second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell Redirection Standard Input The file (or stream) representing input, which is connected to the keyboard Standard Output The file (or stream) representing output, which is connected to the display Standard Error The file (or stream) representing error messages that emanate from the command or shell.This is also connected to the display

second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell Redirection A group of UNIX commands read and write to these files A command is designed to send output to this file not to the terminal similarly, it is not designed to accept input from the keyboard, but from the standard file which it sees as a stream All commands using streams will always find these files open and available

second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell Redirection Even though the shell associates each of the files with a default physical device, can unhook a stream from its default device when it see some special characters in the command line we as users of UNIX have to instruct the shell to do that by using symbols like > and < in the command line

second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell Redirection Standard Input This file can represent three input sources The keyboard, the default source A file using redirection with the < symbol ( metacharacter) Another program using a pipeline

second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell Redirection Standard Input wc without an argument and have no special symbols like < and | in the command line; wc obtains its input from the default source apache[kkhan:301] wc Standard input can be redirected It can come from a file or a pipeline

second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell Redirection Standard Input wc with the filename as argument apache[kkhan:302] wc /etc/passwd /etc/passwd

second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell Redirection Standard Input wc with a character apache[kkhan:302] wc < /etc/passwd On seeing the <, the shell open disk file. /etc/passwd, for reading It unplugs the standard input file from its default source and assigns it to /etc/passwd

second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell Redirection Standard Input wc reads from standard input which has earlier been reassigned by the shell to /etc/passwd wc has no idea where stream came from; it is not even aware that shell had to open the file on its behalf! Input from both file and Standard Input cat – foo cat foo – bar