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:
- loop through all the files in the directory
- grep for space in the filename
- capture results of grep operation ($?)
- Do an if test to see if it did have a space
- If it did, echo the filname out and use sed to replace spaces with underscores.
- Use mv command to rename file
- Maybe echo out a nice message to the user
- End if, end loop
Here is a step-by-step guide for those of you who would like extra help.
To pass off
Submit a screenshot of your script and proof that it worked.
Last Updated 12/15/2017