macOS Error: /bin/bash: bad interpreter: Operation not permitted

I recently attempted to execute a Bash script in Terminal on my Mac but received an error message:

/bin/bash: bad interpreter: Operation not permitted

It turns out that this is often due to the "quarantine" filesystem metadata (extended attributes) being set for the file, preventing it from being executed.

To view the extended attributes for a file (called ""), execute the command:

xattr -l

You should see one of the attributes listed as being set as To remove it from the file, execute:

xattr -d

If you view the extended attributes list again, you should now see the "quarantine" attribute is gone and you can execute the script.