File handling script
For a first script, this is great, and I am impressed.


your structure is neat
you are using loops properly
you are using variable substitution which is 'advanced'


The script appears that it will work for all the standard cases, and, I have seen much worse in 'production' code.

So, as a beginner, well done.

What's next?


the edge cases are going to kill this script - spaces in file names.
the logging and error handling could be better
I recommend basename and dirname instead of the variable regexes you use:

dirname: http://linux.die.net/man/1/dirname
basename: http://linux.die.net/man/1/basename (note that basename path/to/file.pdf .pdf returns file)

consistency on for->do loop - you have do on the next line once, and then for ... ; do the next time. Either is fine, but be consistent.


All of the error-handling, logging, and the spaces-in-files can be solved easily by using a function for running commands. Also, the "$@" construct in bash is 'special'

Consider the bash function:

function runcmd {
    echo "$@"
    # Fail if the command fails...
    "$@" || exit 1
}


So, this function will print the command, and then will run it, and exit the script if the command fails.

Now, instead of structures like:


            echo cp $working_directory/$folder_name/$f $new_filename
            cp $working_directory/$folder_name/$f $new_filename



you can do:

            runcmd cp "$working_directory/$folder_name/$f" $new_filename


and you will still get the echo, you will get the new error handling, and you will handle spaces in names just fine.