I want to see if a folder exists. In the script file if I use:
#!/bin/bash
batch_folder=~/Desktop/
if [ -d $batch_folder ]
then
echo "Dir exists."
else
echo "Dir doesn't exists."
fi
I get as result the correspoding echo. But when I prompt for the path with the read command I'm getting everytime that the directory doesn't exists even if it indeed exists. This is my script:
#!/bin/bash
read -e -p "Batch folder location: " batch_folder
if [ -d $batch_folder ]
then
echo "Dir exists."
else
echo "Dir doesn't exists."
fi
I also tried in the if statement to use as variable "$batch_folder", ${batch_folder}, "${batch_folder}" but none of these works.
I know that the problem is in how the read command saves the variable, because in my first example, if I set batch_folder='~/Desktop/' I'm getting the same result as with the read command.