I was writing an if statement which checked if a file is readable and exists by doing the following:
if [[ -r \"$upFN\" && -f \"$upFN\" ]]; then
....
fi
AFAICT, there is no way to combine them further. As a portability note, [[ expr ]]
is less portable than [ expr ]
or test expr
. The C-style &&
and ||
are only included in bash so you might want to consider using the POSIX syntax of -a
for and and -o
for or. Personally, I prefer using test expr
since it is very explicit. Many shells (bash included) include a builtin for it so you do not have to worry about process creation overhead.
In any case, I would rewrite your test as:
if test -r "$upFN" -a -f "$upFN"
then
...
fi
That syntax will work in traditional Bourne shell, Korn shell, and Bash. You can use the [
syntax portably just as well.