Skip to content
Fragmented Development

Creatively trying to prevent bash script execution

While working on a project, I was wondering if I could make it very difficult to execute a script. I'm creating bash functions in separate files, and they're replacing scripts that used to be executed directly. I am removing execute permissions, but some well-meaning future self might try and "fix" them by re-adding those permissions. Could I stop them from being executed in other ways?

I had a hunch, so I slightly edited the shebang line. You don't need to specify a real shell; I've seen awk scripts that specify it should be run with the awk binary, so why not throw in a curve ball?

#!/usr/bin/false
echo 'This aught to be source-able, but will fail if it is executed'

Here are the results of running this various ways, from an existing bash prompt: mixed success at best!

Not terribly useful, but curious? Definitely.

Tags: terminal bash


Add Your Comment