Presentation is loading. Please wait.

Presentation is loading. Please wait.

Jozef Goetz, 2007 1 expanded by Jozef Goetz, 2006 Credits: Parts of the slides are based on slides created by textbook authors, Syed M. Sarwar, Robert.

Similar presentations


Presentation on theme: "Jozef Goetz, 2007 1 expanded by Jozef Goetz, 2006 Credits: Parts of the slides are based on slides created by textbook authors, Syed M. Sarwar, Robert."— Presentation transcript:

1

2 Jozef Goetz, 2007 1 expanded by Jozef Goetz, 2006 Credits: Parts of the slides are based on slides created by textbook authors, Syed M. Sarwar, Robert Koretsky, Syed A. Sarwar

3 Jozef Goetz, 2007 2 Objectives To describe what a UNIX/LINUX shell is To describe briefly some commonly used shells

4 Jozef Goetz, 2007 3 what a UNIX/LINUX shell acts as an interface between the user and the UNIX/LINUX kernel goal: interpret the user’s cmds Shell = Command Interpreter Shell command can be internal - built-in cmd (part of the shell process - bg, cd, continue, echo, exec) or external cmd (grep, more,cat, mkdir, rmdir, ls) a file in the form of a binary executable program file or a shell script to terminate a shell press

5 Jozef Goetz, 2007 4 how it works after reading the user’s cmd, it determines whether cmd is internal own code is executed or external cmd search for a file that has the name of the cmd by searching several directories the search path is determine in the shell variables PATH (or path in the TC shell) You can view the search path by using echo $PATH

6 Jozef Goetz, 2007 5 PATH and path variables search PATH variable defined in a hidden file called.profile or.login in a system start-up file or start-up file (ha dot file -.bashrc for Bash and.cshrc file for TC shell) in your home directory. in TC shell (separated by “ “ ) in Bourne, Korn, and Bash shell (separated by “:” ) // set path, the search starts with ~/bin and then with. // ~ represents a home directory

7 Jozef Goetz, 2007 6 PATH and path variables To change the search path temporary - change the value of PATH PATH=~/bin:$PATH:. - The search path has been modified by 2 directories, ~/bin and. (current directory) To change the search path permanently you need to change it in the corresponding “.” dot file

8 Jozef Goetz, 2007 7 Intro to UNIX Shell The UNIX/LINUX shell is a program that starts running when you log on and interprets the commands that you type.

9 Jozef Goetz, 2007 8 Which Shell Suits Your Needs? reach common-level interface good programming language good features of sh and csh and is a superset of sh more adv programming features than tcsh equally powerful in their interactive use

10 Jozef Goetz, 2007 9 Table 4.1 Shell Locations and Program Names chsh – change the default shell chsh –l available shells with a path [jgoetz jgoetz]$ chsh -l /bin/bash /bin/sh /bin/bash2 /bin/tcsh /bin/csh /bin/badsh

11 Jozef Goetz, 2007 10 Shell Similarities exec /bin/csh - the same as issuing command csh

12 Jozef Goetz, 2007 11 Table 4.2 Shell Similarities and Dissimilarities

13 Jozef Goetz, 2007 12 Table 4.2 Shell Similarities and Dissimilarities

14 Jozef Goetz, 2007 13 Table 4.3 Some Useful Shell Built-In Commands

15 Jozef Goetz, 2007 14 Ways to Change Your Shell When you 1 st logon your default shell will be shown by typing: $ echo $SHELL /bin/csh $ chsh –l // gives you a list of all shells available You can change your shell one of 2 ways: 1. You can change to a new default for every subsequent login session on your system Changing the default shell: $ chsh // may not working on your system ask you for your login password then type complete path shell: e.g. /bin/tcsh 2.You can create additional shell sessions running on top of, or concurrently with, the default shell Create or run additional shells on top of your default shell $ echo $ SHELL /usr/bin/sh $ csh // new one % // use ps to test it or exec /bin/csh

16 Jozef Goetz, 2007 15 Start-up Files Initial system start-up file has initial settings of important variables for the shell and some other utilities /etc/profile When you start particular shell the corresponding shell start-up file found in the user’s home dir initially configured by the administrator executes:.profile // Bourne, Korn.cshrc.kshrc // Korn.bashrc.zshrc.tcshrc

17 Jozef Goetz, 2007 16 Table 4.5 Some important Shell Startup Files for Bash and TC Shells 1 2 3 bash 4 bash 1. When you log on and your login shell is Bash, it first executes commands in the /etc/profile file, if this file exists. 2. It then searches for the ~/.bash_profile, ~/.bash_login, or ~/.profile file, in this order, and executes commands in the first of these that is found and is readable. 3. When you start an interactive Bash shell, it executes commands in the ~/.bashrc file, if this file exists and is readable. 4. When a login Bash exits, it executes commands in the ~/.bash_logout file. When started non-interactively to run a shell script (see Chapters 15 and 16), Bash looks for the environment variable BASH ENV to find out the name of the file to be executed. Numbers show possible sequence of command execution from the corresponding file

18 Jozef Goetz, 2007 17 Table 4.5 Some important Shell Startup Files for Bash and TC Shells 1 2 3 bash 4 bash 1 for tcsh 2 for tcsh 3 for tcsh 4 for tcsh If your shell is a TC shell, it executes commands in the /etc/csh.cshrc or /etc/.cshrc file, if it exists and is readable. A login shell then executes commands in the /etc/csh.login file, if it exists. 1.Every shell (login or non-login) then executes commands in the ~/.tcshrc file (or the ~/.cshrc file if ~/.tcshrc does not exist), followed by reading the ~/.history file. 2. and 3. A login shell then executes commands in the ~/.login and ~/.cshdirs files. 4. When a login TC shell exits, it executes commands in the /etc/csh.logout and ~/.logout files, if they exist and are readable

19 Jozef Goetz, 2007 18 set | more gives you shell variables values to set a variable set history = 10 for csh (to get it do: exec /bin/csh) setenv | more or setenv variable settings Shell Start-up Files and Environment Variables

20 Jozef Goetz, 2007 19 Environment Variables seen in shell start-up files C shell are in lowercase, others are Bourne and Korn shells

21 Jozef Goetz, 2007 20 Displaying files: display all contents of f1, f2: cat f1 f2 more f1 f2 pg f1 f2 // for some shells

22 Jozef Goetz, 2007 21 Communication Commands Communication Commands: $ who // check the user name to whom you want to talk $ mesg [y|n] // permit execution write or talk $ write user [tty] $ talk user [tty] - shows 2 sections of the screen: sender and receiver $ biff [y|n] // notification on/off

23 Jozef Goetz, 2007 22 Utility Commands (Contd)

24 Jozef Goetz, 2007 23 Command Aliases p.55[3] The alias command can be used to create pseudonyms (nicknames) for commands they can be placed in ~/.profile or ~/.login executes when you log on but typically in a shell start files.bashrc (.cshrc for TC shell) every time you start Tcsh or Bash

25 Jozef Goetz, 2007 24 Command Aliases Syntax for the alias command is: alias [name [ = string ] …] // for Bourne, Korn, Bash shells alias l=‘ls –la’ alias [name [ string ] ] // C shell alias l ‘ls –la’ alias list all aliases remove it unalias ls // remove ls unalias –a // remove all

26 Jozef Goetz, 2007 25 alias Command Examples The \!* string is substituted by the actual parameter passed to the given command

27 Jozef Goetz, 2007 26 Displaying System Up Time uptime 1:16pm up 28 days, 10:44, 2 users, load average: 0.04, 0.01, 0.00 displays the duration of time the system has been running since it was last booted, # of users and some additional info

28 Jozef Goetz, 2007 27 Shell Metacharacters These are the characters other than letters and digits that have special meaning to the shell. They cannot be used in shell commands without specifying them in particular way Allow you to specify multiple files in multiple directories in one command line.

29 Jozef Goetz, 2007 28

30 Jozef Goetz, 2007 29

31 Jozef Goetz, 2007 30 Examples of Shell Metacharacters $ lpr -Pspr [0-9][a-zA-Z].html print on the spr printer, P specifies the printer name, then the names of all the files as follows: 2 chr file names with the first chr digit and 2 nd being an uppercase or lowercase letter $ $ ls lab[0-9]??.c lab11a.c lab1a1.c lab123.c lab4ab.c displays 6 chr long files with.c extension

32 Jozef Goetz, 2007 31 Examples of Shell Metacharacters $ lpr -Pspr [0-9][a-zA-Z].html print on the spr printer, P specifies the printer name, then the names of all the files as follows: 2 chr file names with the first chr digit and 2 nd being an uppercase or lowercase letter $ $ ls lab[0-9]??.c lab11a.c lab1a1.c lab123.c lab4ab.c displays 6 chr long files with.c extension


Download ppt "Jozef Goetz, 2007 1 expanded by Jozef Goetz, 2006 Credits: Parts of the slides are based on slides created by textbook authors, Syed M. Sarwar, Robert."

Similar presentations


Ads by Google