Bash: Unescaped Left Brace in Regex

A strange message was recently received from a Bash script running under Linux Mint 18:

Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/%{ <-- HERE (.*?)}/ at /usr/bin/print line 528.
Error: no such file "test\n"

Slightly confusing, as it reads like a Perl error, rather than bash. Below is another variety of the same thing

Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/%{ <-- HERE (.*?)}/ at /usr/bin/print line 528.
Error: no "print" mailcap rules found for type "text/plain"

The answer was very simple in both cases. I had accidentally put a Perl command into a Bash script. This is enough to throw the “mailcap” error, for example:

#!/bin/bash

print "test"; # That's Perl, not Bash

Add a carriage return (‘print “test\n”‘), and you get the “no such file” version instead.

Root Cause

Of course, Bash is invoking /usr/bin/print, a soft link to /usr/bin/run-mailcap, a 600 line Perl script designed to process MIME files. Nothing to do with writing to the terminal. Use echo instead. Or, perhaps switch from Bash to Ksh.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.