I have to get some files from a device and store them in a directory with a particular name. I'm writing a script that does this, but one of the first things it does is it checks if the directory with the wanted name already exists.
The device version is what determines the name of the directory, but the formatting is off. From my device I get the following number: NUM=10-2-2
I have to reformat it to 10.2.2, so I use NUM=$(echo $NUM | tr "-" ".")
This is the name of a directory. The full path, then, would be /var/www/myServer/10.2.2
.
However, the following code:
Filepath=/var/www/myServer/$NUM
if [ -d $Filepath ]; then
echo the directory exists
else
echo the directory does not exist
fi
always tells me the directory does not exist. But if I declare the variable Filepath
directly (i.e. Filepath=/var/www/myServer/10.2.2
) I get the desired result. Why does this happen?
The output of the tr
command is as follows:
~$ <command-that-gets-version-number> | tr "-" "."
10.2.2
Why does this happen? Any ideas at all would be helpful.
I am running this on Ubuntu 11.x