Suppose the following code :
# Comprueba que el archivo existe y se puede leer
function fileExist(){
if [[ ! -e ${PATH}/$1 || ! -r ${PATH}/$1 ]]
then echo "ERROR_505"
echo "Fichero no accesible"
exit 5
fi
}
I have verified that the data is correct when entering the function by adding the line echo ${PATH}/$1 just before the conditional: the path ( ${PATH}/$1 ) arrives correctly and is correct. However, even though the file $1 exists and is readable, it gets into the conditional and prints the error (but it shouldn't).
Why doesn't the conditional work? Thanks.
When a conditional is enclosed
||
in double brackets[[]]
this operation does not work as expected unless the operation is with string or arithmetic operators .In this case you are using file test operators , and from the looks of it the first line should be like this to run correctly:
In this link you will find more information about test constructions.