CS 330 Lecture 2 – Shell Scripting
Agenda
- what ?s
- who you are
- toolsmiths?
- duality
- redirection, expansion, and substitution
- some scripts
- find biggest files
- recycle instead remove
- mass email
TODO
- Read chapter 13 through 13.2.1.
- If you are thirsty for more:
- Optional challenge: write a one-liner to change permissions of all files and their descendants to be others-readable (without qualification) and others-executable (if and only if the file’s owner has execute permissions)? Such a “sensitive” command is useful on a server, where you want to give execute permissions to subdirectories and scripts but not regular files.
- Two questions and two observations on a 1/4 sheet for Monday.
The UNIX Way
Doug McIlroy said:
This is the Unix philosophy: Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.
Code
newfunc
#!/bin/sh
echo "jfaksdfhaskfhasdkjfhsadkfjhasdkjfs"
exit 7
bigfiles
#!/bin/sh
du | sort -rn | head
safe_rm
#!/usr/bin/env zsh
mkdir -p ~/.junkies
for i in $@; do
mv $i ~/.junkies/${i:t}.$RANDOM
done
massmailer
#!/usr/bin/env zsh
for i in $(cut -f2 -d, here.txt); do
echo "Delete this." | mail -s "[CS 330] Real Good Price on Stuff" -r johnch@uwec.edu $i@uwec.edu
done
Haiku
It’s not to save time
My brain dies a little bit
When I use my mouse