I do not understand the following expression.
function abc(){
..............
...............
[[ -f $filename]] && return 0 || return 1
}
As per tutorial if there is a file exists with filename variable name then this function returns 1 otherwise it returns 0.
I understand && || operator ,but how is this statement getting the desire result?
As per me,In case [[ -f $filename ]] evaluates false ,then one statement of && is false then result of and is false.Now it goes to OR and if first operand is 0 it returns result of second operand so it should return 1,but instead it is returning 0.
How is this being evaluated?
0is "true" and everything else is "false," so the function should return 0 if the file exists, which it does.