teaching machines

CS 330 Lecture 2 – Hello, Shell

January 28, 2015 by . Filed under cs330, lectures, spring 2015.

Agenda

TODO

Questions

Code

fixext

#!/usr/bin/env zsh

newext=$1
shift

for i in $@; do
  yes | mv $i ${i:r}.$newext
done

safe_rm

#!/usr/bin/env zsh

trash=$HOME/.junkies

mkdir -p $trash
for i in $@; do
  mv $i $trash/${i:t}.$RANDOM
done

bigs

#!/bin/sh

du | sort -nr | head -n 20

massmail

#!/usr/bin/env zsh

for i in $(cut -f2 -d, grades.csv | sed 1d); do
  echo "Delete this email." | mail -s "[CS 330] Real Good Deal on Chronometers" $i@uwec.edu
done

dirdiff

#!/usr/bin/env zsh

d1=$1
d2=$2

for i in $d1/*; do
  basename=${i:t}
  if [[ ! -e $d2/$basename ]]; then
    echo "No $basename in $d2!"
  elif [[ -d $i ]]; then
    $0 $i $d2/$basename
  else
    diff $i $d2/$basename >/dev/null
    if [[ $? -ne 0 ]]; then
      echo "Files $i and $d2/$basename differ."
    fi
  fi
done

Haiku

on simplicity and complexity:
UNIX has two ways
Do one thing and do it well
Be “glueser”-friendly