Sunteți pe pagina 1din 15

The shell

Presented by :Simant kumar chaudhary MCA student(AEC)


simant kumar chaudhary (MCA Student)

------Quoting------ quoting is a way to turn off the meaning of special character. When we write a special character within a single quote then meaning of special character is turn off. ex:$ echo *?[8-10] or $ echo *?[8-10] *?[8-10] it simply print the quoted character Because double quotes have also its on feature.

Spacing
The space has also special meaning to shell. When a shell find contiguous space or tab then it compress all space or tab into a single space. ex:$ echo the shell compress multiple space the shell compress multiple space $echo the shell compreees multiple space the shell compress multiple space because of double quotes.

simant kumar chaudhary (MCA Student)

Spacing and quoting in echo


There are some command the use \ to remove the special meaning . The \ slash appear with a character. ex:$ echo Enter your name= \c enter your name=_ the output is not in next line but in same line Echo escape sequence manipulate the cursor movements \t A Tab \n A new line \f A form feed (page skip) $ echo \t this massage is broken here\n\ninto three Line this message is broken here three line In Bash shell the echo used with e option $ echo e Enter your name= \c Enter your name=_
simant kumar chaudhary (MCA Student)

Redirection
Many of the command that we used to sent to their output to terminal. There are actually designed to use character stream without knowing source and destination. The stream are only sequence of byte that may command see the input and output. Unix treats these stream as a file and group of UNIX command read and write these to a file. A command is not design to usually send output to terminal. It is not designed to except input from keyboard either but only from stander file The third stream all error message known by the program. Some three important file used by shell.
Stander input :- the default source is keyboard Standard output :- the default destination is terminal Standard error :- the default destination is terminal

Note :-The above three file are set by the shell at login time and close at the logout time.
simant kumar chaudhary (MCA Student)

Stander output
Command like cat and who send their output as character stream . this stream is called like stander stream of command .by default this appear on the terminal. The symbol used to redirect is > and >> we can redirect output to a disk.
Example :- $ who > newfile $ cat newfile output:- user

The > stands stander output to redirected , open a new file The >> use , if we want to redirect our output into a existing file without disturbing the previous content. Example:- $ who >> newfile $Cat newfile output:User Root
simant kumar chaudhary (MCA Student)

Redirection using wild card


Redirection has feature to use wild card Example:- $cat puli?? >pop We can also combine two or more command and redirect their output. Stander output has three destination file terminal pipe

simant kumar chaudhary (MCA Student)

Stander input
some command are design to take their input also as a stream. This stream represent stander input to a command. The command wc display the word , line and character . example :- $ wc 2 ^ 32 25 * 50 30*25 + 15 ^ 2 output :- 3 9 39 If we store the above imput to a file name cal.lst When a metacharecter < is used with wc , like example :- $ wc < cal.lst output :- 3 9 39 Cal.lst file is input for wc command . Source input stream has also three source file keyboard pipe example:- $ bc < cal.lst > result.lst $ cat result.lst output:- 4294967296 1250 975 simant kumar chaudhary (MCA Student)

Stander error
When we enter a incorrect command or try to open nonexistent file then an error is displayed. ex:- $ cat bar cat: can not open bar: no such file or directory The three file stream is assigned by a number
stander input ------- 0 Stander output -------- 1 Stander Error --------- 2

simant kumar chaudhary (MCA Student)

Pipe
When a sequence of command is combined together in a way , a pipeline is said to be formed. To illustrate the pipe let us consider an example. ex:- $ who | wc-l who is said to be piped to wc The pipe method using two commands Disadvantage of pipe :- The process is slow. The second command cant act unless the first complete. We require an intermediate file that has to be removed after the wc command has to be complete its run. When handling large file ,temporary file can be build up easily and eat up disk space in no time. Ex:- $ who | wc-l the output of who is redirecte d as input of wc

simant kumar chaudhary (MCA Student)

Pipe is third source and destination between stander input output. ex :- $ ls | wc l > pop.lst $ cat pop.lst output :- 5 There are no restriction of command we can use in pipe line but we must know the behavioural property and arrenge proper position. General form of command line command1 | command2 |command3 |command4

simant kumar chaudhary (MCA Student)

tee: splitting a stream

The UNIX tee command breaks up its input into two component One component saved in file and other component connected to stander outptut. tee does not perform any filtering action on its input ,it give out exactly what it takes. example :- $ who | tee user.lst output :root tty01 december 06 08:27 simant tty02 december 06 10:40 piyush tty 03 december 06 11:30 and the other component saved in file user.lst $ cat user.lst root tty01 december 06 08:27 simant tty02 december 06 10:40 piyush tty 03 december 06 11:30 $ who | tee user.lst |wc l 3 The advantage of tee is appearance twice one in terminal and other in file

simant kumar chaudhary (MCA Student)

Command substitution

The shell enable argument of command to be obtained from stander output of another. While the pipe (|) combine two command in form of output of first command is input of another command. Command substitution is enable when the back quotes and the enclosed command are placed within double quotes example :- $ echo the date today is `date ` output : the date of today is tue december 06 10 : 19 est 1999 And if we enter in command prompt (same as above) $ echo there are `ls |wc l` file in cutrrent directory output: there are 58 file in current directory But if we $ echo there are `ls | wc l` file in current directory output: there are `ls |wc l` file in current directory

simant kumar chaudhary (MCA Student)

Shell variable
We can define a variable both command line and shell script these variable are called shell variable. A shell variable is string type which mean that the value is stored in ASCII rather than a binary format. There is no any type is necessary to declare a Shell variable. example :- $ x=20 $ echo $x 20 The variable name is like alphabet , number , underscore but remember that first character must be a letter. The shell is case sensitive. The x and X has different in UNIX shell. To remove a variable , use unset . all shell variable are initialized by default NULL value. If we assign a string in variable we use single quote. Like a=simant
simant kumar chaudhary (MCA Student)

Shell treatment of command line


When we enter a command then hitting Enter then the sequence is well defined and assume the following order.
Parsing :- the shell break up command into word using space and delimiter and quotes . Variable evaluation :- all word preceded by a $ is evaluated unless quote are escaped . Command substitution :- any command surrounded by back quotes are evaluated by the shell and output inserted in the place it found. Redirection :- then the shell look for character > , < and >> to open the file that they point to. Wild card interpretation :- the shell scan the command line for wild card and replace them with list of file name that match the pattern. Path evaluation :- it finally looks the PATH variables to determine the sequence of directory.

simant kumar chaudhary (MCA Student)

End of shell

simant kumar chaudhary (MCA Student)

S-ar putea să vă placă și