Chapter 3: Using the Shell - PowerPoint PPT Presentation

1 / 41
About This Presentation
Title:

Chapter 3: Using the Shell

Description:

Exploring the Bash Shell (continued) Flexible ... Executed each time user starts bash shell. User can add configuration information ... – PowerPoint PPT presentation

Number of Views:112
Avg rating:3.0/5.0
Slides: 42
Provided by: class8
Category:
Tags: bash | chapter | shell | using

less

Transcript and Presenter's Notes

Title: Chapter 3: Using the Shell


1
Chapter 3Using the Shell
  • The Complete Guide to Linux System Administration

2
Objectives
  • Use common features of the shell to work at the
    command line
  • Manipulate variables in the shell to control your
    working environment
  • Redirect data at the command line
  • Edit text using the vi editor
  • Print basic files from the command line

3
Exploring the Bash Shell
  • Shell
  • Command program
  • Accepts input from keyboard
  • Uses input to run commands or otherwise control
    computer
  • Started when terminal window opened

4
Exploring the Bash Shell (continued)
  • Flexible
  • Interact with any file that you have permission
    to access
  • Start any program on system
  • Use special features of shell to work more
    efficiently

5
The Shell Prompt
  • Set of words or characters indicating that shell
    is ready to accept commands
  • Default prompt example
  • Nwells_at_inverness nwells
  • When logged in as root, prompt character changes
    to hash mark,

6
The Functions of a Shell
  • Shell purpose
  • Make it easy for users to run programs and work
    with files in Linux
  • Run programs
  • Pass parameters to program being started
  • Behavior
  • If command succeeds, no response
  • If command fails, error message printed

7
The Functions of a Shell (continued)
  • Shell has many built-in features
  • Help you work with files and commands
  • Script
  • Program
  • List of commands stored in text file

8
Different Types of Shells
  • Shell has no special relationship to Linux kernel
  • Can use any shell
  • Bourne shell
  • Original shell for UNIX
  • Called sh
  • Old program with limited functionality
  • Bash
  • Default shell for all Linux systems

9
Different Types of Shells (continued)
  • Shells fall into two groups
  • Bourne shell programming style
  • C shell programming style
  • Shell started for each user is determined by
    settings in user account
  • Each user on system can select preferred shell
  • Immediately run different shell
  • Enter name of shell program

10
Entering Commands
  • Features designed to simplify process of entering
    commands
  • Tab completion
  • Enter part of file or directory name
  • Press tab key
  • Shell fills in remainder of name
  • Command history
  • Records each command

11
Entering Commands (continued)
  • Command history
  • Quickly call up and repeat any command from list
  • Press the up arrow key at command prompt
  • Press enter to execute command
  • History command
  • Displays entire history list
  • Bang
  • !

12
Entering Commands (continued)
  • Locate previously executed command
  • Use history number
  • Use beginning of command
  • Search history list

13
The Shell Start-up Process
  • Scripts executed when you log in to Linux
  • Initialize various parts of environment
  • Script /etc/profile executed on first log in
  • Contains configuration information that applies
    to every user on system
  • Profile script
  • Found in users home directory
  • Specific to single user

14
The Shell Start-up Process (continued)
  • Some systems
  • Additional scripts are executed when user logs in
  • When user starts shell
  • Additional scripts executed
  • bashrc script
  • Executed each time user starts bash shell
  • User can add configuration information

15
The Shell Start-up Process (continued)
16
Using Aliases
  • Alias
  • String substituted for another string at shell
    prompt
  • Alias command
  • Define how shell will substitute one string for
    another
  • Format
  • alias ltstring entered by usergtltstring
    substituted by the shellgt
  • Enter without arguments to see list of current
    aliases

17
Command-line Expansion
  • Shell can make many different substitutions,
    including
  • Aliases
  • Variables
  • Command substitution
  • Special characters
  • Place commands in single quotes
  • Executed first by shell

18
Command-line Expansion (continued)
  • Special characters
  • Place in single quotes
  • Precede with
  • Example \n
  • Other special characters
  • ?

19
Command-line Expansion (continued)
  • Avoid command-line expansion
  • Escape individual characters
  • Using \
  • Single quote
  • Double quote

20
Shell Variables
  • Shell variable
  • Name that can have value assigned to it
  • Can be number or string of text
  • Typically created using all uppercase letters
  • Environment variable
  • Typically defined during initialization of
    operating system or users shell
  • Can be accessed by any program

21
Shell Variables (continued)
  • env command
  • Start program with environment variable setting
    that is not part of current environment
  • Only used for started program
  • Set command
  • Displays list of all environment variables
  • Echo command
  • View value of single environment variable

22
Shell Variables (continued)
  • Export command
  • Makes newly created environment variable
    available to other programs
  • PATH environment variable
  • Contains list of directories that shell searches
    each time command is executed
  • PS1 environment variable
  • Defines shell prompt for bash

23
Data Redirection
  • Standard input channel
  • STDIN
  • Keyboard
  • Standard output channel
  • STDOUT
  • Monitor
  • Standard error
  • STDERR

24
Data Redirection (continued)
  • Data can be redirected from standard channels
  • Pipe
  • Connects output channel of one command to the
    input channel of another command
  • Example ls /etc sort

25
Data Redirection (continued)
26
Data Redirection (continued)
  • Mail command
  • Basic e-mail client
  • Use from command line to create e-mail message
  • Format mail -s "subject line" e-mail_address

27
Editing Text with vi
  • Text editor
  • Single most important utility for system
    administrator
  • Many different text editors are available for
    Linux
  • Text-mode editors
  • vi
  • emacs
  • pico
  • Joe

28
Editing Text with vi (continued)
  • Very powerful program
  • Available on virtually every Linux system
  • Not easy to use
  • Must learn to use at least basic features in
    order to work as Linux system administrator
  • Memorize keystroke sequences
  • Work without any onscreen prompts

29
Editing Text with vi (continued)
  • To start
  • vi command
  • Can be followed by name of file to edit
  • Modal editor
  • Keystrokes are interpreted differently depending
    on mode you are working in

30
Editing Text with vi (continued)
  • Modes
  • Command mode
  • Insert mode
  • Replace mode
  • Begin in command mode
  • Return to command mode by pressing Esc key

31
Editing Text with vi (continued)
32
Editing Text with vi (continued)
33
Editing Text with vi (continued)
34
Editing Text with vi (continued)
35
Editing Text with vi (continued)
36
Printing from the Command Line
  • Quickly configure printer attached to parallel
    port
  • Print files directly from command line

37
Setting Up a Printer
  • Print queue
  • Printer definition
  • Associate physical printer with named printer
    definition
  • Set up printer via GNOME desktop interface
  • Choose system settings
  • Print
  • Follow steps in dialog

38
Printing From a Command Line
  • lpr command
  • Print from command line
  • Uses series of filters based on type of file to
    print
  • lpoptions command
  • Save commonly used list of options

39
Summary
  • Shell
  • Command interpreter used to start programs
  • Many shells are available
  • Tab completion
  • Helps to quickly enter long file and directory
    names
  • Command history
  • Quickly reenter previously entered command

40
Summary (continued)
  • Scripts executed when
  • User logs in
  • New shell opened
  • Aliases
  • Shell replaces text on command-line entry with
    different text
  • Shell expands text on command line in several ways

41
Summary (continued)
  • Environment variables store values that programs
    can access
  • Flow of data between programs can be changed
    using redirection operators on command line
  • Linux supports numerous text editors
  • After setting up printer, print files from
    command line using lpr command
Write a Comment
User Comments (0)
About PowerShow.com