+ All Categories
Home > Documents > UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or...

UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or...

Date post: 01-Jan-2016
Category:
Upload: tiffany-wells
View: 246 times
Download: 0 times
Share this document with a friend
Popular Tags:
24
UNIX/LINUX Shells • Shell is an UNIX/LINUX command interpreter. • Shell command can be internal or external. • The code to execute an internal command is part of the shell processes. (Ch. 13) • The code to process an external command resides in a file in the form of a binary executable program file or a shell script.
Transcript
Page 1: UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.

UNIX/LINUX Shells

• Shell is an UNIX/LINUX command interpreter.

• Shell command can be internal or external.• The code to execute an internal command is

part of the shell processes. (Ch. 13)• The code to process an external command

resides in a file in the form of a binary executable program file or a shell script.

Page 2: UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.

UNIX/LINUX Shells• Shell executes command entered from the

keyboard.• By pressing <^D> at the beginning of a new

line, shell terminates.• Shell assumes the first word in a command

line is the name of the command.• Shell assumes any of the remaining word

starting with a hyphen (-) are options and that the rest of them are the command arguments.

Page 3: UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.

UNIX/LINUX Shells• How shell command are processed?

1. Read your command line.2. Determines whether the command is an

internal or external command.3. Process all internal command by using

corresponding code segment that are within its own code. (See Ch. 13 for commands)

4. Execute an external command by searching directories in the file system structure, looking for a file that has the name of the command. (See Ch. 7 for commands)

Page 4: UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.

UNIX/LINUX Shells• Shell process all internal commands by

using the corresponding code that are within its own code.

• Shell searches several directories in the file system structure, looking for a file that has the name of the command.

• Shell variable: PATH (or path in the TC shell)

• search path• echo $PATH (Bash); echo $path (TC

Shell)

Page 5: UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.

UNIX/LINUX Shells

• Common Shells and their locations

Page 6: UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.

Figure 4.1 Shell families and their relative functionalities

Page 7: UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.

UNIX/LINUX Shells• login shell: (your default shell) When you log on, one particular type of shell

starts execution.• Change your default shell: 1: Ask your system administrator 2: Using shell command such as chsh.

Page 8: UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.

UNIX/LINUX Shells• Three ways to change your shell. 1) by changing to a new default shell for every subsequent

login session. 2) by creating additional shell sessions running on top of,

or concurrent with , the default shell. 3) by changing your shell for only the current login

session.

Page 9: UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.

UNIX/LINUX Shells• 1) Change to a new default shell.• To find out which shell you're currently using, enter: echo $SHELL

• To see a list of available shells, enter: cat /etc/shells

• On computers running Linux, enter: chsh –s newshell (Your password might be asked.) Replace newshell with the full pathname of the shell you want to use.

Enter your password when prompted, and the system will change your shell.

e.g. chsh newshell (Solaris) e.g. chsh username newshell (HP-UX) e.g. chsh (AIX, Tru64)

Page 10: UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.

UNIX/LINUX Shells• 2) Create additional shell to run at the same

time as your default shell.• $ echo $SHELL• /bin/bash• $ tcsh• % psPID TTY TIME CMD

1025 pts/0 00:00:00 bash

1041 pts/0 00:00:00 tcsh

1048 pts/0 00:00:00 ps

Page 11: UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.

UNIX/LINUX Shells• 3) Change your shell by using the exec

command (for only the current login session)

For eaxmple, if you have determined that your current shell is Bash and you want to change to the TC shell, simply type:

exec /bin/csh

Page 12: UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.

Shell Similarities and Disimilarities (continued on next slide)

Page 13: UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.

Shell Similarities and Disimilarities (continued from previous slide)

Page 14: UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.

Shell Start-Up Files and Environment Variables

• Each Linux system has an initial system start-up file, usually in /etc/profile. (Initial settings of important environment variables for shell and some other utilities)

• Shell start-up files (When you start a shell) are in a user’s home directory as ~/.profile or in a particular shell’s profile or login file in each user’s home directory.

• dot files or hidden files

Page 15: UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.

Shell Startup Files for Bash and TC Shells

Page 16: UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.

Shell Environment Variables

Page 17: UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.

Creating and Displaying Directories

(; separates commands)

• pwd

• mkdir tmp; rmdir tmp; rm –rf (3 commands)

• ls; ls –l; ls –C; ls –ac; ls –last (5 comamnds)

• ls –C linuxbook/examples (1 command)

• cd; cd ~teng; cd ~; (3 commands)

Page 18: UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.

Displaying files

• cat file_name• more file_name (one screen @ a time)

• more sample phones (one screen @ a time for both files; The contents of the sample file displays first.)

• pg file_name (The pg command is similar to the more command.)

Page 19: UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.

Printing Files• lpr is the off-line printer... (BSD, SUN)

lp is just a frontend to the lpr. (System V)

• lpr –P printer1 sample (-P: printer device)

• lpr –P spr –n 3 sample (-n: number of copies)

• lp –d printer1 sample (-d: printer device)

Page 20: UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.

Create Pseudonyms for Commands

• alias [ name [=string]…] Bash shell• alias [ name [string]] TC shell• Command aliases can be placed in a system

start-up file, the ~/.profile or the /.login file.• Usually they are placed in a shell start-up

file; the .bashrc file (Bash) and the .cshrc file (TC shell)

• The ~/.profile or ~/.login file executes when you log on.

• The ~/.cshrc or ~/.bashrc file executes every time you start Tcsh or Bash.

Page 21: UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.

Some Useful Aliases

$ unalias ls

$ alias

Page 22: UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.

Some Useful Aliases

• $ unalias –a

• $ alias

• $

Page 23: UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.

Shell Metacharacters (continued on next slide)

Page 24: UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.

Shell Metacharacters (continued from previous slide)


Recommended