A little scripting

About a month ago I created a little bash script to copy an image file from a temporary folder to my journal folders on my PC and Dropbox. The original script worked well enough but it lacked error checking plus I knew I’d have to eventually make changes to use it with next years folders.

The original script took two arguments from the command line, the file to be copied and moved, and the month which designated the appropriate folder. I added a third argument, the four-digit year used in the parent folder. Since the year would be incorporated with in the folder names and the month at the end, I changed the method used to build the folder names using the += operator.

In creating the tests to check the validity of the file to be manipulated and the existence of the created folders, I found it useful to create a function that would print the proper syntax should any of the tests fail.

I also developed a test that after the copy and the move operations checks for the existence of the file in each of the destination folders and displays the operation’s success or failure.

This was a good scripting exercise for me and the first time I’ve used a function in a utility script. I’d like to improve my scripting skills but the tutorials I have have given an elementary understanding but provide little in the way of practical examples and the usage of functions. I’ll be looking for other tutorials to advance my knowledge.

 

Advertisements
%d bloggers like this: