The question is simple; Is it possible to convert a bash script into an executable? and if it is, how can it be done?
To make the program executable from anywhere for all users, we can add it to the global profile settings in /etc/profile. We should note that /etc/profile and ~/. bash_profile are specific to the Bash shell. Other shells will likely use different locations.
The simplest way to compile Bash is: cd to the directory containing the source code and type `./configure' to configure Bash for your system. If you're using csh on an old version of System V, you might need to type `sh ./configure' instead to prevent csh from trying to execute configure itself.
It's possible, but you don't want to.
In places where support for compiling a script into a standalone executable is available, this is done by putting a copy of the interpreter into the executable. This is, thus, much larger than the script alone.
The execution model used by bash, unfortunately, is innately slow: Almost all functionality is provided by external commands; and simple commands' arguments, or even their names, can be modified by the result of expansion operations. This level of dynamicism makes effective compilation for performance impossible. (zsh supports a precompilation process, but the benefit is limited, mostly to the process of parsing itself).
Take shc
, for instance: It literally passes the script's original source as a command-line argument. Thus, that source can be read simply by reading the command-line arguments out of /proc
, or using strace
.
As they say, "security by obscurity is no security at all" -- anyone who's reasonably competent could trivially extract any passwords or other content obfuscated in this way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With