Table of Contents

Project: Pipes n' dirs

A project for Systems Programming by Brandon Kennedy during the Fall 2011 Semester.

This project was begun on 12-15-2011 and is anticipated to take 1 day.

Objectives

By undertaking this project i hope to refresh on some scripting that I learned in unix/linux fundamentals.

Prerequisites

In order to successfully accomplish/perform this project, the listed resources/experiences need to be consulted/achieved:

Background

I am hoping to regain some lost knowledge of shell scripting from unix/linux fundamentals. I will be using pipes, file I/0, I/0 redirection and some other things to brush up on the basics of shell scripting.

Scope

This script will receive a pathname from the user and will calculate how many files are in certain ranges like [a-g]. It will then output the directory path and the records of how many files are in each range to a file called rawdata. only errors should be printed to the screen.

Attributes

State and justify the attributes you'd like to receive upon successful approval and completion of this project.

Code

1
#hist.sh, a scripting program for systems programming and unix/linux fundamentals, by Brandon Kennedy
#program accepts a directory pathname and outputs to the file "rawdata"
touch rawdata
chmod 660 rawdata
echo -n "Please enter the the path to a directory:  "
read directory
echo ""
 
echo "Directory: $directory" > rawdata
cd $directory
echo "" >> rawdata
 
echo -n "Total Files: " >> rawdata
echo $(ls | wc -w) >> rawdata
echo "" >> rawdata
 
echo -n "(a-g): " >> rawdata
ls -d [a-gA-G]* | wc -w >> rawdata
echo "" >> rawdata
 
echo -n "(h-m): " >> rawdata
ls -d [h-mH-M]* | wc -w >> rawdata
echo "" >> rawdata
 
echo -n "(n-s): " >> rawdata
ls -d [n-sN-S]* | wc -w >> rawdata
echo "" >> rawdata
 
echo -n "(t-z): " >> rawdata
ls -d [t-zT-Z]* | wc -w >> rawdata
echo "" >> rawdata
echo "" >> rawdata

Reflection

Shell scripting is an extremely powerful tool, and I hope i can dig into it more in the comming semesters. I deffinitely have a lot to learn, as I struggled getting even some basic tools to work. One of the harder things was 'ls -d [a-g]* | wc -w' I at first couldent get ls to only look at the directoy name, instead of traversing it, till i found the -d tag.

References

In performing this project, the following resources were referenced: