teaching machines

CS 330 Lecture 2 – Shello

January 25, 2017 by . Filed under cs330, lectures, spring 2017.

Dear students,

Let’s start with some quick review questions. Discuss these questions and their answers with a neighbor. If you don’t talk to someone about these, you fail the exercise.

  1. Java : methods :: shell : __________
  2. What do strings look like in a shell script?
  3. Suppose I have username and domain variables. How do I produce an address variable?
  4. How do I write a loop that processes all PNG files in the current directory?
  5. What is the exit status of this script?
    if test -e $0; then
      echo 10
    else
      echo 20
    fi

Then we’ll write some scripts:

  1. A file that reverses itself.
  2. Zip a directory DIR to file DIR.zip.
  3. Bookmark a directory for later return.
  4. Send files to limbo/recycling bin, rather than hell/non-existence.
  5. Send a mass email.

Here’s your TODO list for next time:

Sincerely,

iam.sh

#!/bin/sh

if test -e $0; then
  echo 10
else
  echo 20
fi

lines

#!/usr/bin/tail -r
Rachael
Matthew
Bingo
Petey F
Marge N
Bill Dollar

zippydoodir

#!/usr/bin/env zsh

if [ $# -ne 1 ]; then
  echo 'Ack!'
  echo "Usage: $0 dir"
  exit 1
fi

dir=$1
zip -r $dir.zip $dir