I wrote a fairly simple backup script for my Linux machine in bash. Essentially it is a recursive script that looks at all the files in the directory, sees if they exist in the backup, then sees if they are newer than the backup, and then backs them up if necessary. So, here is the one problem I can't yet solve...
When the script is called it takes from two to an infinite number of arguments. The first is the backup destination, and the following arguments are sources. It goes through this list with the $@ variable in a for loop. When an argument is a directory, it calls itself with the appropriately altered destination directory and a /* added on to the source directory. So, for example, if I wanted to backup /source to /backup and one of the arguments was a subdirectory /source/sub then this is how it would work...
# First I call the script
backup /backup /source/*
# One of the files in /source/* is the subdirectory /source/sub, so the script calls itself recursively like so...
backup /backup/sub /source/sub/*
# And so on
So, this is the way it works essentially. Now, before all this occurs there's a test to see if the arguments exist (to catch human error, of course). The problem I'm having is that if these files have two consecutive spaces in their names, they return a false value in the test. So, if the variable that we're testing is $arg, this is how I have the test written...
if [ -e "$arg" ] ; then
echo "$arg does not exist!"
I have the double quotes so that files with any spaces at all are valid. I just don't know why files with two spaces aren't. Also, when it outputs the error, the error does NOT display two spaces, but only one. I don't know why this is. I can't tell if the problem is in getting the value of $arg (i.e. the variable never gets two spaces), if it's in the test, or in what * returns or what. I'm kind of a newbie at this. Any recommendations?
Thanks very much in advance.