I have a one-line Perl search and replace that looks something like this:
perl -p -i -e 's/foo/bar/' non-existent-file.txt
Since the file does not exist (which is not intentional, but it is part of an automatic build script, so I want to protect against this), Perl completes this error:
Can't open non-existent-file.txt: No such file or directory.
However, the exit code is still zero:
echo $?
0
Am I doing something wrong? Should I modify my script or the way I invoke Perl? I naively believed that since Perl could not find the file, it would exit with non-zero code.
source
share