Bellevue University CIS 240 - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Bellevue University CIS 240

Description:

Allow you to create your own commands. Contain interpreters that recognize shell scripts ... First character is upper or lower case a-z ... – PowerPoint PPT presentation

Number of Views:65
Avg rating:3.0/5.0
Slides: 18
Provided by: JohnRu
Category:

less

Transcript and Presenter's Notes

Title: Bellevue University CIS 240


1
Bellevue UniversityCIS 240
  • Overview of
  • Shell Programming

2
Shell Programming
  • What is a shell
  • Variables
  • Control Structures
  • Functions
  • Commands
  • Arithmetic expressions

3
What is a shell?
  • It is a command interpreter
  • A program that enables the user to interact with
    the computer.

4
Shells
  • Recognize the standard UNIX command set
  • Allow you to create your own commands
  • Contain interpreters that recognize shell scripts

5
Shells are powerful because they allow you to
create a single command that executes several
commands. This saves time
6
Variables
  • Places in memory used to hold values
  • Can be initialized and altered
  • Are represented by variable names
  • Do not need to be declared before they are used
    (declaring means identifying the name and
    variable type)

7
Variable names
  • Follow the same convention as C names
  • First character is upper or lower case a-z
  • Next characters are upper or lower case letters,
    numbers, or underscores
  • The maximum length depends on your version of
    UNIX

8
Variable Types
  • Default is string
  • May be declared as follows
  • -u Upper Case
  • -l Lower Case
  • -i Integer
  • -r Read only
  • -L Left justified
  • -R Right justified

9
Example of variable
  • Execute these two commands.
  • typeset i x5
  • echo x

10
Using the echo command
  • echo x returns x
  • echo x returns the contents of variable x

11
Environment Variables
  • Special variables that pertain to your
    environment
  • Upper case letters

12
Common Environment Variables
HOME Contains the users home directory IFS Inte
rnal Field Separator PATH Contains the full path
used for commands PS1 Primary
prompt PS2 Secondary prompt SHELL Contains the
pathname of the current shell
13
Control Structures
  • if Decision making statement
  • case Selection statement
  • for Counting loop
  • while Decision loop

14
Functions
  • Subprogram that is called by the main program
  • Used to add structure to shell scripts
  • Must be defined before use
  • Variables can be passed to functions
  • Functions can return variables

15
Commands
  • List of common shell script commands is on PP 132
    and 133 of your text

16
Arithmetic Operators
  • Addition
  • - Subtraction
  • Multiplication
  • / Division
  • Modulo
  • ! Negation (not)
  • Equal to
  • ! Not equal to
  • lt Less than
  • lt Less than or equal to
  • gt Greater than
  • gt Greater than or equal to

17
Differences between shell scripts
  • Older shells
  • x0
  • for i in 1 2 3
  • do
  • xexpr x 10
  • echo i x
  • done
  • Newer shells
  • X0
  • for i in 1 2 3
  • do
  • x((x10))
  • echo i x
  • done
Write a Comment
User Comments (0)
About PowerShow.com