Page 409 - DCAP103_Principle of operating system
P. 409

Principles of Operating Systems



                   Notes         which displays the graphical login screen where a user enters his username and password.
                                 When working on Linux systems through a graphical interface, users may use mouse clicks to
                                 run applications or open file, drag and drop to copy files from one location to another, etc. In
                                 addition, users may invoke a terminal emulator program, or xterm.

                                 14.1.3 Shell
                                 Although Linux systems have a graphical user interface, most programmers and sophisticated
                                 users still prefer a command line interface, called the shell. Often they start one or more shell
                                 windows  from  the graphical user interface and just work in them. The  shell command  line
                                 interface is much faster to use, more powerful, easily extensible, and does not give the user RSI
                                 from having to use a mouse all the time. Below we will briefly describe the bash shell (bash).
                                 It is heavily based on the original UNIX shell, Bourne shell, and in fact its name is an acronym
                                 for Bourne Again Shell. Many new shells are also in use (ksh, csh, etc.), however, bash is the
                                 default shell in most Linux systems. When the shell starts up, it initializes itself, then types a
                                 prompt character, often a per cent or dollar sign, on the screen and waits for the user to type
                                 a command line.
                                 When the user types a command line, the shell extracts the first word from it, assumes it is the
                                 name of a program to be run, searches for this program, and if it finds it, runs the program. The
                                 shell then suspends itself until the program terminates, at which time it tries to read the next
                                 command. What is important here is simply the observation that the shell is an ordinary user
                                 program. All it needs is the ability to read from the keyboard and write to the monitor and the
                                 power to execute other programs. Commands may take arguments, which are passed to the
                                 called program as character strings.
                                 For example, the command line
                                 cp src dest

                                 invokes the cp program with two arguments, src and dest. This program interprets the first one
                                 to be the name of an existing file. It makes a copy of this file and calls the copy dest.

                                 Not all arguments are file names. In head 20 file the first argument, 20, tells head to print the first
                                 20 lines of file, instead of the default number of lines, 10. Arguments that control the operation
                                 of a command or specify an optional value are called flags, and by convention are indicated with
                                 a dash. The dash is required to avoid ambiguity, because the command head 20 file is perfectly
                                 legal, and tells head to first print the initial 10 lines of a file called 20, and then print the initial
                                 10 lines of a second file called file. Most Linux commands accept multiple flags and arguments.
                                 To make it easy to specify multiple file names, the shell accepts magic characters, sometimes
                                 called wild cards. An asterisk, for example, matches all possible strings, so
                                 ls *.c
                                 tells ls to list all the files whose name ends in .c If files named x.c, y.c, and z.c all exist, the above
                                 command is equivalent to typing
                                 ls x.c y.c z.c

                                 Another wild card is the question mark, which matches any one character. A list of characters
                                 inside square brackets selects any of them, so

                                 ls [ape]*
                                 lists all files beginning with ‘’a’’, ‘’p’’, or ‘’e’’. A program like the shell does not have to open
                                 the terminal (keyboard and monitor) in order to read from it or write to it. Instead, when it
                                 (or  any  other  program)  starts  up,  it  automatically  has  access  to  a  file  called  standard  input



        402                               LOVELY PROFESSIONAL UNIVERSITY
   404   405   406   407   408   409   410   411   412   413   414