Unix Shells - PowerPoint PPT Presentation

Loading...

PPT – Unix Shells PowerPoint presentation | free to view - id: 23da3-M2NkM



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

Unix Shells

Description:

Korn Shell (/usr/bin/ksh): Provides more environmental control then Bourne shell ... Incorporates features of Korn and C shells ... – PowerPoint PPT presentation

Number of Views:136
Avg rating:3.0/5.0
Slides: 20
Provided by: jomae
Category:
Tags: korn | shells | unix

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Unix Shells


1
Unix Shells
  • References
  • man pages
  • Ray and Ray, "Visual QuickStart Guide Unix"
  • Watters, Chapter 11

2
Overview
  • Purpose of shells
  • Common shells
  • Shell commands
  • bash
  • POSIX environment variables
  • Configuring bash shell using .bashrc

3
Purpose of Shells
  • Interface between user and kernel
  • User may be person or program
  • Provide access to system calls

4
Common Shells
  • Bourne Again SHell (/usr/bin/bash) sh-compatible
    and incorporates features of Korn and C shells
  • C shell (/usr/bin/csh) uses C syntax and
    provides feature not found in Bourne shell
  • Command aliasing
  • History substitution
  • Job control
  • Korn Shell (/usr/bin/ksh) Provides more
    environmental control then Bourne shell
  • Bourne shell (/usr/bin/sh) standard job control
    shell
  • Provides variable, command and filename
    substitution
  • Enhanced Berkley C shell (/usr/bin/tcsh) C shell
    with file name completion and command line editing

5
Other Shells of Interest
  • Remote shell (/usr/bin/rsh) connects to
    specified host and executes specified command
  • Job control shell (/usr/bin/jsh) same as sh
  • Z shell (/usr/bin/zsh) Includes many
    enhancements to Korn shell
  • Command line editing
  • Built-in spelling correction
  • Programmable command completion
  • History

6
Identifying Current Environment
  • Default shell echo SHELL
  • Current search path echo PATH
  • What's your login info who am i
  • More info about user finger loginID
  • Much more info about env set OR env
  • Who's logged in who

7
Useful Commands
  • Display content of a file cat filename
  • Change directory cd dirpath
  • Change permissions on file or directory chmod
    mode objName
  • Clear display clear
  • Copy file cp source destination
  • Append text to a file echo string filename
  • Search directory for file find path string
  • Search text for string text grep i string
  • View screen at a time less filename OR command
    less
  • View content of a directory ls OR ls dirPath
  • Get help on a command man command
  • Create a directory mkdir dirName
  • Change name of a file mv oldName newName
  • Move a file mv fileName dest
  • Display present working directory pwd
  • Delete a file rm filename
  • Delete a directory rmdir dirName

8
Commands to Lookup
  • alias
  • awk
  • banner
  • batch
  • chown
  • cut
  • date
  • groups
  • groupadd
  • kill
  • ls
  • netstat
  • paste
  • ps
  • passwd
  • read
  • script
  • sh
  • spell
  • sort
  • su
  • talk
  • tail
  • time
  • touch
  • useradd
  • vi

9
bash
  • Bourne shell (sh) compatible command language
    interpreter
  • Executes commands for standard input or files
  • Incorporates features of Korn and C shells
  • Conformant implementation of IEEE POSIX Shell and
    Tools specification (IEEE 1003.2)

10
POSIX Standard
  • Portable Operating Systems Interface
  • Standards defines a standard operating system
    interface and environment
  • Command interpreter (or "shell")
  • Common utility programs to support applications
    portability at source code level

Source http//www.unix.org/single_unix_specificat
ion/
11
POSIX Basic Regular Expressions
  • Regular expressions used for text processing
  • Includes decoding shell commands
  • Zero or more characters followed by
  • Ordinary characters any character in supported
    character set, except for special characters
  • Special characters have special properties in
    certain context
  • Matching is by bit pattern used for encoding
    character, not on graphic representation of
    character.

12
POSIX Environment Variables
13
Safe Environment Variables to Change
  • CDPATH
  • COLUMNS
  • EDITOR
  • ENV
  • HISTFILE
  • HISTFILESIZE
  • HISTSIZE
  • HOSTFILE
  • IGNOREEOF
  • LINES
  • MAIL
  • MAILCHECK
  • MAIL_WARNING
  • noclobber
  • PATH
  • PROMPT_COMMAND
  • PS1 prompt
  • PS2
  • PS3
  • PS4
  • TMOUT
  • VISUAL

14
Types of bash Shells
  • Login shell
  • Default shell for user
  • Or shell started with --login option
  • Interactive
  • Standard input and output connected to terminal
  • Or shell started with i option
  • Non-interactive
  • Shell invoked with name sh
  • Does not read startup files

15
bash Interactive Invocation
  • Login shell executes following in order unless
    --noprofile used at shell's startup
  • /etc/profile
  • /.bash_profile
  • /.bash_login
  • /.profile
  • Not login shell executes /.bashrc
  • If exists
  • If not inhibited by option norc
  • Option --rcfile filename forces file named to
    execute as bashrc file and /.bashrc will not run

16
Configuring bash
  • Edit /.bashrc
  • Some syntax
  • Comment symbol
  • Continuation symbol \
    represents pressing Enter key
  • Using environment variables ENV_VAR
  • Setting environment variables ENV_VARvalueexpor
    t ENV_VAR1, .., ENV_VARn
  • Creating aliases alias newCmd'command'

17
Example .bashrc File
  • This is a comment in this example
  • bash run control file.
  • Adding to the search path
  • PATHPATH/usr/sbin
  • Change prompt
  • PS1"\u_at_\host\w\\"
  • Make environment changes work
  • export PATH, PS1
  • Create aliases
  • alias ll'ls al'
  • alias renamemv

18
Special Symbols for bash Prompt
  • \u Show current loginID
  • \w Show current directory with path
  • \W Show current directory without path
  • \t Show time
  • \d Show date
  • \n Force newline
  • \h Show short hostname
  • \H Show long hostname
  • \s Show shell's name
  • \v Show shell's version
  • \! Show command history number

19
Example PROMPT_COMMAND
  • meant to be sourced from your bash environment
  • this will display a colored error code if the
    previous function
  • returned an error, or just the regular prompt
    otherwise.
  • JPM
  • showIfError ()
  • AUX?
  • if AUX -gt 0 then PREFIX"\\033133m\
    AUX " else PREFIX"" fi
  • PS1"PREFIX\\033132m\\w\\03300m\\
    "
  • PROMPT_COMMANDshowIfError

20
Sending Messages
  • mesg -y
  • Allows messages
  • If mesgn, no messages
  • write DestLoginID
  • DestLoginID is danaID of destination
  • Type message and press Enter key
  • To terminate use Ctrl-d
  • Ctrl-d is End Of Transmission

21
Let's Try Some of This
  • What shell are you using?echo SHELL
  • If it's not bash, then change to
    bash./usr/bin/bash
  • Change the prompt to say "loginID rocks!
    "PS1"\u rocks!"
  • Find out who's logged in.who
  • Find out more about someone logged in.finger
    loginID
  • See what you have done.history
  • Send yourself a message.mesg ywrite
    loginIDHi, Dude!d

22
Summary
  • Shell interpret commands and control jobs
  • Common shells sh, bash, csh, ksh, tcsh
  • ls /bin lists general commands
  • ls /usr/sbin lists system admin commands
  • man cmdName tells about command named
  • Shells are customizable
  • bash is sh-compatible and POSIX compliant
  • She sells seashells by the seashore

23
Questions?
About PowerShow.com