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:

  1. What does it mean for a directory to be executable?
  2. Write a command to run program place, reading from file bets and appending its output to file log.
  3. What will file .. report?
  4. Your program webify generates a lot of HTML. Write a command to only show the img 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
  • 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:

  1. Bookmark a directory for later return.
  2. Send files to limbo/recycling bin, rather than hell/non-existence.
  3. Send a mass email.
  4. Show the biggest files in a directory.
  5. 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.



du -s * | sort -nr | head



cd $(cat ~/.dirmark)



pwd > ~/.dirmark


Leave a Reply

Your email address will not be published. Required fields are marked *