It’s the details, silly Perl error

Just today I was troubleshooting what seemed to be a spurious error in the logs of a script I wrote. The script itself isn’t all that important to this discussion but what I found in troubleshooting irked me to no end and I felt like I had to write about it.

In my script I have two places where I run a “find” command via the system() call to do very specific work. In this case doing recursive permissions and file mode changes on a directory.

Take a look at the offending line?

Looks innocent doesn’t it?   What you have there is an interpolation bomb for a lack of better term for it.  The error I was seeing was “find: missing argument to `-exec'” which after a bit of thought I realized the command the shell was actually seeing was “ find mydir -type f -exec chmod 0644 {} ; ” which would be missing the backslash as find would expect to be there. Whoops.

The reason for this would be everything inside the double quotes gets interpolated and the interpolation in play here was an unnecessary escape of the semicolon.  Modifying my code with a single quote thusly:


You know… really I should be using File::Find instead… but sometimes laziness gets the better of me…


Copyright DevOps — In the Trenches 2019
Tech Nerd theme designed by Siteturner