I'm trying to test if a file exists by passing the contents of a variable to the test -e of bash. The variable looks like this :
FILE1='/etc/wherever/whatever'
When i do :
[[ -e "$FILE1" ]]
$? equals to 1, and it says it can't find the file (above path is an example....)
Tried several options: double quotes around the filepath instead of single quotes (variable is obtained from a line in a file)
Found out it only works if I put the filepath in the file I read without any quotes. But that would be a problem when using filenames withe spaces in it.
So, to clarify: 1) file contains lines that are read one by one 2) columns in line are split using IFS into separate variables 3) one variable is a filename, that is enclosed in single quotes 4) a [[ -e $variable ]] can't find the file.
What would be the correct syntax, please ?
Aucun commentaire:
Enregistrer un commentaire