I have a several logical AND commands and in the middle is a perl command that edits a file in-place.
echo before && \
perl -pe 's/foo/bar/g' -i qux && \
You might use
perl -pe ... < file instead of
perl -pe ... file. In this case the shell will already complain if the file does not exist without even invoking perl. But this can not be used together with the
Or since you want to use the
-i switch you might check that the file is writable before using it. Not that this checks for
qux being both file and writable because being only one of these is not enough (maybe one needs to check for readable too).
[ -f qux ] && [ -w qux ] && perl -pe ... -i qux