CS 330 Lecture 40 – Shell scripting, or Why I love Linux
Agenda
- shell scripting
- programs are methods
- speed and terseness
- caters to file manipulation
- globbing
- loops
- I/O redirection
- some problems
- resizing a bunch of images
- comparing two directories
- change extensions on a bunch of files
- checking for new mail
- sending spam
- finding big files
- preparing code for blog posts
Code
shrinken.sh
#!/bin/sh mkdir -p dialup_friendlies for img in *.JPG; do convert $img -resize 300x300 dialup_friendlies/$img done
checkmail.sh
#!/bin/sh mailx -A uwec -H | grep '^ U' > /dev/null if [ $? -eq 0 ]; then echo "You have mail." fi
spam.sh
#!/usr/bin/env zsh for username in $(cat usernames.txt); do echo Sending mail to $username... mailx -A uwec -s "[CS 330] Lecture Spam" -r johnch@uwec.edu $username@uwec.edu < message.txt done
Haiku
Languages are streets.
Paving them smooth is pointless…
Until you’re hauling stuff.
Paving them smooth is pointless…
Until you’re hauling stuff.