170 likes | 719 Views
What is a Shell. A shell is a program that acts as the interface between the user and UNIX system It acts as an interpreter or translator It allows user to enter commands for the operation system to execute
E N D
What is a Shell • A shell is a program that acts as the interface between the user and UNIX system • It acts as an interpreter or translator • It allows user to enter commands for the operation system to execute • It hides the details of the kernel’s operation from the user. So, < and > are used to redirect files, | to pipe up jobs, $(…) to output from a subprocess, etc. • Shells can be command-line-driven or graphical
csh other programs kernel Hardware bash X windows System Shell Model
Because UNIX is modular, there are many different shells in use. They are • Bourne shell (sh) • C shell (csh, tcsh and zsh) • Korn shell (ksh, pdksh) • Bourne Again shell (bash) • Rc • Except for the C shell, all of these are very similar • They are closely aligned with the shell specified in the X/open 4.2 and POSIX 1003.2 specifications
POSIX lays down the minimum specification • X/Open extends the specification to provide a more friendly and powerful shell • To identify which shell is using: ps (process status) or echo $SHELL
Pipes and Redirection • Input/Output Redirection • All CPU operations have I/O. The keyboard, for example, provides standard input (stndin), while the monitor displays standard output (stndout) and standard error (stnderr)
Standard Output Command Standard Input Standard Error • Every UNIX command has a source for standard input and a destination for standard output • The input to a command normally comes from the keyboard, although it also can come from a file. The output from a command normally goes to the monitor or screen. Errors that might result from a command are another form of output and also are displayed on the screen
The UNIX computing environment enables command I/O to be controlled using redirection • Output redirection uses the right angle bracket(>) $ ls –l > lsoutput.txt • To append to the file, >> operator could be used $ ps >> lsoutput.txt • Error output redirection uses the right angle bracket, preceded by the number 2 (2>) $ kill –HUP 1234 > killout.txt 2> error.txt • Input redirection uses the left angle bracket (<) $ more < killout.txt
Standard Output Standard input Command Command | Pipe • Pipes • To connect processes together, use the pipe (|) operator • The pipe passes the standard output of one command as standard input into a following command • command | command • e.g.$ ps | sort > passort.out