Shells Scripts - PowerPoint PPT Presentation

1 / 35
About This Presentation
Title:

Shells Scripts

Description:

Be the penguin. The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL. Freeciv ... Midnight Club 2. Andrew Zaferakis, UNC '02, works for Rockstar San Diego ... – PowerPoint PPT presentation

Number of Views:91
Avg rating:3.0/5.0
Slides: 36
Provided by: andrew345
Category:

less

Transcript and Presenter's Notes

Title: Shells Scripts


1
Shells Scripts
COMP 121-401 UNIX Programming
  • Andrew Nashel
  • nashel_at_cs.unc.edu
  • Department of Computer Science
  • February 6, 2004

2
Course topics
  • Shell scripts
  • Homework

3
Shells scripts
  • Any collection of shell commands can be stored in
    a file called a shell script. Scripts have
    variables and flow control statements like other
    programming languages.
  • There are two popular classes of shells
  • C shell (csh) and variants (tcsh)
  • Bourne shell (sh) and variants (bash, ksh)

4
Invoking scripts
  • There are two ways to launch scripts
  • 1) Direct interpretation
  • csh scriptfile args
  • 2) Indirect interpretation
  • The first line of the file must be
  • !/bin/csh
  • and the file must be executable.

C Shell
5
Variables
  • To set variables
  • set X value
  • Variable contents are accessed using
  • echo PATH
  • To count the number of variable elements
  • echo Y

C Shell
6
Variables contd
  • To create lists
  • set Y (abc 1 123)
  • To set a list element
  • set Y2 3
  • To view a list element
  • echo Y2

C Shell
7
Command arguments
  • A shell script to swap files
  • ! /bin/csh f
  • set tmp argv1
  • cp argv2 argv1
  • cp tmp argv2
  • The number of arguments to a script
  • argv

C Shell
8
if-then-else
  • if ( expr ) simple-command
  • if ( expr ) then
  • commandlist-1
  • else
  • commandlist-2
  • endif

C Shell
9
if-then-else contd
  • An example
  • if (argv 2) then
  • echo we need two parameters!
  • else
  • set name1 argv1
  • set name2 argv2
  • endif

C Shell
10
Loops
  • while ( expr )
  • commandlist
  • end
  • foreach var ( worddlist )
  • commandlist
  • end

C Shell
11
switch
  • switch ( str )
  • case string1
  • commandlist1
  • breaksw
  • case string2
  • commandlist2
  • breaksw
  • default
  • commandlist
  • endsw

C Shell
12
goto (Considered harmful!)
  • To jump unconditionally
  • goto label
  • A label is a line such as
  • label
  • The classic paper on why not to use goto
  • Go To Statement Considered HarmfulEdsger W.
    Dijkstra, CACM, March 1968

C Shell
13
An example script
  • ! /bin/csh -f
  • foreach name (argv)
  • if ( -f name ) then
  • echo -n "delete the file 'name' (y/n/q)?"
  • else
  • echo -n "delete the entire dir 'name'
    (y/n/q)? "
  • endif
  • set ans
  • switch (ans)
  • case n continue
  • case q exit
  • case y rm -r name continue
  • endsw
  • end

C Shell
14
Homework
  • Due Monday
  • Write a shell script that reads a file and
    replaces a particular text string with another,
    all input given interactively.
  • Hint Use sed for text replacement.
  • This is your final graded assignment!

15
Homework contd
  • Example
  • ./myscript
  • File to read news.txt
  • Search text Duke
  • Replacement text Dookie
  • Dookie University
  • Department of Mathematics
  • Weekly Calendar

16
Hmmmm.
  • Okay, shell scripts are useful, but a little
    boring.

17
Unix Games!
COMP 121-401 UNIX Programming
  • Andrew Nashel
  • nashel_at_cs.unc.edu
  • Department of Computer Science
  • February 6, 2004

18
SpaceWar
  • SpaceWar may be the most important computer game
    ever. The first version was developed for the
    PDP-1 at MIT in 1960. The game has been under
    essentially constant development since.

19
SpaceWar contd
  • The first CRT display was a converted
    oscilloscope used to play SpaceWar. The first
    trackball (and thus, the first mouse) was a
    SpaceWar control at MIT. It is said that Ken
    Thompson salvaged a PDP-1 and created a new
    operating system, now called UNIX, so that he
    could play SpaceWar.

20
Spacewar contd
The PDP-1
Real 133 gamers
21
Nethack
  • A Rogue-like classic dungeon crawl game retrieve
    the Amulet of Yendor!

22
XPilot
  • The classic multiplayer 2D shooter.

23
XBill
  • Whack the computer hacker and free the computers
    from the awful virus!

24
Xmame
  • Multiple Arcade Machine Emulator

25
Xconq
  • A general purpose strategy game.

26
Tux Racer
  • Be the penguin.

27
Freeciv
28
FlightGear
29
BZFlag
30
UNC Games!
COMP 121-401 UNIX Programming
  • Andrew Nashel
  • nashel_at_cs.unc.edu
  • Department of Computer Science
  • February 6, 2004

31
Adventure
  • Warren Robinett, a former UNC-CS professor, wrote
    Adventure, the first action-adventure video game,
    in 1978 and it sold over 1 million copies.

He also founded The Learning Company for
educational software.
It included the first easter egg!
32
Ratchet and Clank
  • Max Garber, UNC 02, works at Insomnic Games, Los
    Angeles

33
Buffy and Wrath
  • Stephan Sherman and Vince Scheib, 02 work for
    The Collective in Newport Beach, CA

34
Midnight Club 2
  • Andrew Zaferakis, UNC 02, works for Rockstar San
    Diego

35
Vicious Cycle
  • Greg Coombe wont ever graduate.
Write a Comment
User Comments (0)
About PowerShow.com