Unix Shells Unix Shells u Command Line Interpreter

  • Slides: 22
Download presentation
Unix Shells

Unix Shells

Unix Shells u Command Line Interpreter – once logged in, login gives control to

Unix Shells u Command Line Interpreter – once logged in, login gives control to a shell – it prompts for input, then parses, interprets, finds and executes the commands you type – similar to Windows “Command Prompt”, but more sophisticated and more user friendly u. A High-Level Programming Language – shell script is a program contains a series of commands – you can let the system perform those commands by typing the file name of the script – similar to. BAT batch files under MS-DOS, but again much more sophisticated

Shells vs. Graphical User Interfaces (GUIs) u GUIs are more friendly to beginners –

Shells vs. Graphical User Interfaces (GUIs) u GUIs are more friendly to beginners – lead you by the hand – “point and click” interface requires little experience u Shells are often better for experienced users – shells tend to be faster, more efficient, and flexible vfewer steps to do things vdo not need to change input devices (keyboard vs. mouse and keyboard) – but, you must know command names and syntax u Most modern Unix systems offer both a GUI and a Shell interface

Unix Shells u Many shells to choose from. . . u sh: The Bourne

Unix Shells u Many shells to choose from. . . u sh: The Bourne Shell – – the original Unix shell S. R. Bourne designed it at Bell Labs not very "user friendly”, but good for programming sh or a reasonable facsimile comes packaged with virtually every Unix system u csh: The C-shell – a shell whose syntax is more “C”-like – command history and job control vmake it very popular as a CLI – comes with most Unix systems

Unix Shells u tcsh: The T C-Shell – updated C-shell with better “line-editing”, access

Unix Shells u tcsh: The T C-Shell – updated C-shell with better “line-editing”, access to command history, and command file name completion – default shell on GAUL u bash: The Bourne Again Shell – aimed at providing a public domain version of the Bourne shell – default shell for Linux – implemented as a part of GNU project by public efforts u ksh, zsh, tsh, . . .

Changing Your Shell u Default shell is the shell you are given after you

Changing Your Shell u Default shell is the shell you are given after you login to the system u Changing your shell. . . – Your default shell can be changed using the “chsh” command on Unix. v. More on this later – By typing “sh”, “csh”, “tcsh”, “bash”, etc. v. Run another type of shell as a “subshell” v. After you exit from the subshell, you will come back to the old one v. Your default shell is unchanged

Which Shell(s) Do We Teach? u For the CLI aspects of the shell, we

Which Shell(s) Do We Teach? u For the CLI aspects of the shell, we teach tcsh u For programming language aspects, we teach sh u Many Unix users use shells in this way u Many features of sh or tcsh are shared by other shells – e. g. tcsh is really an extension of csh, with some extra features

Issuing Commands u Unix shells issues a prompt for input u A typical prompt

Issuing Commands u Unix shells issues a prompt for input u A typical prompt looks like: obelix[1]> Machine name u Editing Separator History number input: – using arrow keys to move the cursor – using Back. Space or DEL or Ctrl-H to erase a letter – using Ctrl-U to erase the whole line.

Issuing Commands u. A command is typically a program saved in the Unix file

Issuing Commands u. A command is typically a program saved in the Unix file system, or part of the shell. – type the name of the program, press <return> – shell searches for the program and runs it u Most commands take arguments – Operands: file names, numbers, etc. obelix[2] > cat myfile display file "myfile" obelix[3] > expr 1 + 3 – Options: immediately following a ‘-’ or ‘+’ obelix[4] > cat -n myfile obelix[5] > ls -al display file "myfile" with line numbers

Issuing Commands u Stopping and pausing processes – Control-c : terminate current process now

Issuing Commands u Stopping and pausing processes – Control-c : terminate current process now v. Sends SIGINT signal to the process. v. Default setting of receiving a SIGINT is to quit. – Control- : terminate current process now v. Send SIGQUIT signal to the process. v. A core file is usually generated. – Control-z : Pause command now v. Can be restarted using the fg or bg commands v. More on this useful keystroke later. – kill: Kill a process. v. More on this useful command later.

Common Commands (1) u cp for Co. Py Use: obelix[4] > cp file 1

Common Commands (1) u cp for Co. Py Use: obelix[4] > cp file 1 file 2 Action: copy file 1 into file 2 u rm for Re. Move Use: obelix[5] > rm file 2 Action: removes or deletes file 2 u mv for Mo. Ve Use: obelix[6] > mv file 1 file 3 Action: renames file 1 as file 3 Compare: cp file 1 file 3; rm file 1

Common Commands (2) u cat for listing the contents of a file – Use:

Common Commands (2) u cat for listing the contents of a file – Use: obelix[7] > cat file 1 – Results: display the contents of file 1 – Why “cat”? v originally “short” for concatenate v can use: obelix[8] > cat file 1 file 2 v prints file 1 followed by file 2 u more for listing the contents of a file, one screen full at a time – Use: obelix[9] > more file 1 – Results: display the contents of file 1 for a page and pause. Press return for next line. Press space bar to see next page, b to go back one page. Press q to quit.

Common Commands (3) u date what date and time is it? Use: Result: u

Common Commands (3) u date what date and time is it? Use: Result: u cal obelix[10] > date print the time and date print a calendar Use: Result: u hostname Use: Result: u who obelix[11] > cal print the calendar of the month what machine am I on? obelix[12] > hostname print the machine's name who else is logged onto this computer? Use: obelix[13] > who Result: a list of users and some info about them

Common Commands (4) u uptime how long has the machine been up and running?

Common Commands (4) u uptime how long has the machine been up and running? Use: obelix[14] > uptime Result: one line with all sorts of neat stuff u netscape Use: Result: u lynx surf the net obelix[15] > netscape web surfing software that works only under X-windows surf the net Use: Result: obelix[16] > lynx web surfing software that is text-only

Common Commands (5) u echo: print some text Use: Result: u expr: evaluate an

Common Commands (5) u echo: print some text Use: Result: u expr: evaluate an expression Use: Result: u clear: obelix[17] > echo Unix is easy! obelix[18] > expr 1 + 2 3 clear screen Use: obelix[19] > clear Action: clears the screen

Using man u man: View manual pages Use: obelix[20] > man subject Action: Displays

Using man u man: View manual pages Use: obelix[20] > man subject Action: Displays the man page for subject u e. g. “man cat” produces the following:

Important Parts of Manual Pages u Name – The name of the command brief

Important Parts of Manual Pages u Name – The name of the command brief description u Synopsis – A brief overview on how to use the command u Description – More details of what the command does u Options and Operands – Arguments given to the command u Examples u See Also – Related commands

More of man u man -k keyword – list all the commands whose brief

More of man u man -k keyword – list all the commands whose brief description (in the “name” field) contains the keyword – the apropos command does the same thing as executing man -k u man – print out the manual of the command man u man -s n subject – prints man page for subject from section n – man pages are organized into several sections: v. Commands, C reference, File formats, … – man -l subject will list all of the sections containing the subject … a man -s will then find the man page

Alternatives to man u xman – An X-windows interface to man pages – Better

Alternatives to man u xman – An X-windows interface to man pages – Better browsing and searching facilities u info – A hypertext interface to accessing manuals for GNU software (gcc, emacs, info, …) u answerbook – Newer manual pages from Sun in HTML – Also at: http: //asterix. gaul. csd. uwo. ca: 8888 u http: //docs. sun. com/ – Complete set of manuals from Sun

Electronic Mail (1) u We assume you are familiar with e-mail u Your e-mail

Electronic Mail (1) u We assume you are familiar with e-mail u Your e-mail address: – Your e-mail address is made up of two parts v. Your user name. – Generally your login name on GAUL. v. Your domain name. – A collection of users, typically connected to a particular collection of computers v. Your e-mail address will be something like bill@gaul. csd. uwo. ca vgaul. csd. uwo. ca is the "domain name“ for all of the machines in the Undergrad lab

Electronic Mail (2) u There’s u u u a very wide choice of mail

Electronic Mail (2) u There’s u u u a very wide choice of mail programs mail – the “default” mailer – has a command-line interface with lots of commands elm – this is a visual, partially menu-driven mailer – complete, flexible and easy to use – requires that you know the “vi” or “emacs” editor pine – the simplest mailer – “noisy” menu-driven interface, but quite complete – use it if you are unsure of yourself. . . it does the job

Exercise u Use ps to see which shell you are using. u Change your

Exercise u Use ps to see which shell you are using. u Change your shell to another by sh, csh, or tcsh u Use ps again to see how many shells are running; explain why.