CS 330 Lecture 2 – Shell Scripts and Redirection
Agenda
- shell builtin variables
- interpolation
- custom variables
- reusing output
- meday
- custom scripts
- PATH
- permissions
- change extension 1+ files at a time
- command-line arguments
- resizing a bunch of images with convert
- checking for mail
- STDIN and STDOUT and STDERR
- output redirection
- pipes
- subshells
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.
TODO
- Read section Learning the Shell at http://linuxcommand.org/index.php.
- Bring a quarter sheet with two questions and two observations to class.
- Log in to thing-[012] and write your own shell script to do something.
Code
doeday
#!/bin/sh
cal 28 3 $(date +%Y)
imagen
#!/bin/sh
convert -size 1600x1200 plasma: plasma.JPG
convert -size 1600x1200 plasma:blue blue.JPG
convert -size 1600x1200 plasma:tomato-steelblue tomatoblue.JPG
convert -size 1600x1200 plasma:grey50-grey50 plasma-grey.JPG
convert -size 1600x1200 gradient: grad.JPG
convert -size 1600x1200 gradient:yellow ygrad.JPG
convert -size 1600x1200 radial-gradient: cgrad.JPG
fixext
#!/usr/bin/env zsh
for file in $*; do
mv $file ${file:r}.jpg
done
Haiku
Out is the new in
Only cool in the shell though
Don’t eat human waste
Only cool in the shell though
Don’t eat human waste