Handle cases when a script is called with relative or absolute paths

The script can be called in different ways. The user can just use the
filename or use relative/absolute paths. The last case led to errors
with the current script. It mkdir'd 'chapter*' and failed.

The commit will take the name of the shell script ($0) and determines
if there are slashes in it. If so, it removes the everything except
the path, checks if it is really a directory and constructs a correct
path for the for-loop.

The two changes in line 45 and 47 remove everything before the the
last slash including the slash. So especially the title doesn't
contain file paths.