Lab 14

In this assignment you will develop some simple bash shell scripts to allow you to automate repetitive tasks. You will also review other shell commands.

Begin by developing a shell script that will search for files within a directory whose name contains a space. Your script should replace all spaces in a filename with an underscore.

To setup you test environment, create a folder in your home directory called playground. Create test files within playground by executing the following from the command line:

for i in $(seq 1 10); do touch “file $i.txt”; done; for i in $(seq 11 20); do touch “file$i.txt”; done;

List these files to ensure they created properly.

Here is some pseudocode to help you solve this:

  1. loop through all the files in the directory
  2. grep for space in the filename
  3. capture results of grep operation ($?)
  4. Do an if test to see if it did have a space
  5. If it did, echo the filname out and use sed to replace spaces with underscores.
  6. Use mv command to rename file
  7. Maybe echo out a nice message to the user
  8. End if, end loop

Here is a step-by-step guide for those of you who would like extra help.

Lab 14 Walk Through

To pass off

Submit a screenshot of your script and proof that it worked.

Last Updated 12/15/2017