CS 330 Lecture 3 – Shell Scripting, Part 2
Dear students,
We will continue to work with the shell, a world between worlds. A place full of dead mice. Let’s start with a reading review:
- What does it mean for a directory to be executable?
- Write a command to run program
place
, reading from filebets
and appending its output to filelog
. - What will
file ..
report? - Your program
webify
generates a lot of HTML. Write a command to only show theimg
tags.
Now it’s time for a segment I like to call What Does This Do? We’ll spend a moment absorbing each code snippet, and then I’ll ask what they do and what would be a good name for the script.
- WDTD #1
for i in $@; do mv $i $(date +%Y%m%d)_$i done
- WDTD #2
base=$(basename -s .c $1) gcc -o $base $1 && ./$base
- WDTD #3
yes "Got get 'em." | head -n 15
Then we’ll write some scripts:
- Bookmark a directory for later return.
- Send files to limbo/recycling bin, rather than hell/non-existence.
- Send a mass email.
- Show the biggest files in a directory.
- Upload a local file to a web server and let the world see it.
Here’s your TODO list for next time:
- Install Ruby on your Linux installation. Ruby is often installed per user, and one user may have several versions installed. I recommend you do the same. The following shell commands will install RVM (the Ruby Version Manager) and Ruby 2.3.3.
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 \curl -sSL https://get.rvm.io | bash -s stable rvm install 2.3.3 ruby --version
- Watch Introduction to Ruby until at least 17:25.
Sincerely,
big
#!/bin/bash du -s * | sort -nr | head
redir
#!/bin/bash cd $(cat ~/.dirmark)
save
#!/bin/bash pwd > ~/.dirmark