1 / 18

Lecture 2. What Is The Shell ?

Lecture 2. What Is The Shell ?. Spring 2006 Course, Sungkyunkwan University Hyunseung Choo choo@ece.skku.ac.kr. WHAT IS THE SHELL?. The Kernel and the Utilities (1/2) The “UNIX system” is itself logically divided into two pieces The kernel The heart of the UNIX system

Download Presentation

Lecture 2. What Is The Shell ?

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 2. What Is The Shell ? Spring 2006 Course, Sungkyunkwan University Hyunseung Choo choo@ece.skku.ac.kr

  2. WHAT IS THE SHELL? • The Kernel and the Utilities (1/2) • The “UNIX system” is itself logically divided into two pieces • The kernel • The heart of the UNIX system • resides in the computer’s memory from the time the computer is turned on and booted until the time it is shut down • The utilities • reside on the computer’s disk • only brought into memory as requested • virtually every command you know under the UNIX system is classified as a utility

  3. UTILITIES UNIX SYSTEM KERNEL disks Memory WHAT IS THE SHELL? • The Kernel and the Utilities (2/2) • The Shell • A utility program • It is loaded into memory for execution whenever you log into the system [Fig. 1] The UNIX system

  4. login: login: UNIX SYSTEM KERNEL getty getty login: login: getty login: login: WHAT IS THE SHELL? • Logging In (1/3) • A terminal is connected to a UNIX system through a direct wire, modem, or local area network • For each terminal port on a system, a program called getty will be active [Fig. 2] The getty process

  5. WHAT IS THE SHELL? • Logging In (2/3) • The UNIX(init) system automatically starts up a getty program on each terminal port whenever the system is allowing users to log in login: login: sue Password: UNIX SYSTEM KERNEL login getty login: login: getty login: login: [Fig. 3] login started on sue’s terminal

  6. WHAT IS THE SHELL? • Logging In (3/3) • /etc/passwd • After login checks the password you type in against the one stored in /etc/passwd, it then checks for the name of a program to execute sue: fkrIboLrjdkK.:15:47::/usr/sue: pat: MjvntQLddYop.:99:7::/usr/pat:/usr/lbin/ksh bob: j9GTYQzHGwIG.:13:100::/usr/data:/usr/data/bin/data_entry [Fig. 4] /etc/passwd

  7. WHAT IS THE SHELL? • Typing Commands to the Shell (1/3) • When the shell starts up, it displays a command prompt and then waits for you type in a command (Steps 1 & 2) • Each time you type in a command and press the Enter key (Step 3) • The shell analyzes the line you typed and then proceeds to carry out your request (Step 4) • If you ask it to execute a particular program, then the shell searches the disk until it finds the named program

  8. WHAT IS THE SHELL? • Typing Commands to the Shell (2/3) • Once found, the shell asks the kernel to initiate the program’s execution and then the shell “goes to sleep” until the program has finished (Step 5) • If the program reads input from standard input, then it will wait for you to type in input unless redirected from a file or piped from another command (Step 6) • When the command has finished execution, control once again returns to the shell which awaits your next command (Step 7 & 8)

  9. shell shell ls shell $ $ ls $ ls foo rje foo rje $ login: login: login: login: WHAT IS THE SHELL? • Typing Commands to the Shell (3/3) [Fig. 5] Command cycle

  10. WHAT IS THE SHELL? • Log-in cycle • When you log off the system, execution of the shell then terminates and the UNIX system start up a new getty at the terminal that waits for someone else to log in init sh getty login [Fig. 6] Log-in cycle

  11. program execution interpreted programming language variable and file name substitution SHELL environment control I/O redirection pipeline hookup WHAT IS THE SHELL? • The Shell’s Responsibilities [Fig. 7] The shell’s responsibilities

  12. WHAT IS THE SHELL? • Program Execution (1/2) • The shell is responsible for the execution of all programs that you request from your terminal • The shell scans this command line and determines the name of the program to be executed and what arguments to pass to the program • Multiple occurrences of whitespace characters are simply ignored by the shell program-name argument(s)

  13. WHAT IS THE SHELL? • Program Execution (2/2) mv rje/mazewars games [Fig. 8] Execution of mv with two arguments echo when do we eat? [Fig. 9] Execution of echo with four argements

  14. WHAT IS THE SHELL? • Variable and File Name Substitution • Like any other programming language, the shell lets you assign values to variables • The shell also performs file name substitution on the command line • e.g.) *, ?, […] $ ls mrs.todd prog1 shortcut sweeney $ $ echo * mrs.todd prog1 shortcut sweeney $ [Fig. 10] Execution of echo

  15. WHAT IS THE SHELL? • I/O Redirection (1/2) • The shell scans the command line for the occurrence of the special redirection characters <, >, or >> • Before the shell starts execution of the desired program, it redirects the standard output of the program to the indicated file echo Remember to tape Miami Vice > reminder

  16. WHAT IS THE SHELL? • I/O Redirection (2/2) $ wc –l users 5 users $ wc –l < users 5 $ [Fig. 11] Execution of wc –l users [Fig. 12] Execution of wc –l < users

  17. WHAT IS THE SHELL? • Pipeline Hookup • Just as the shell scans the command line looking for redirection characters, it also looks for the pipe character | • For each such character that it finds, it connects the standard output from the command preceding the | to the standard input of the one following the | who | wc -l

  18. WHAT IS THE SHELL? • Interpreted Programming Language • The shell has its own built-in programming language • The shell analyzes each statement in the language one line at a time and the executes it

More Related