Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to convert a bash script into an executable?

The question is simple; Is it possible to convert a bash script into an executable? and if it is, how can it be done?

like image 762
Kalis Avatar asked Jul 07 '15 22:07

Kalis


People also ask

How do I make a bash script executable from anywhere?

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.

Can Bash be compiled?

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.


1 Answers

It's possible, but you don't want to.

  • It won't be effective obfuscation.
  • It won't be smaller.
  • It won't be faster.

It won't be smaller

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.

It won't be faster

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).

It won't be effective obfuscation

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.

like image 106
Charles Duffy Avatar answered Nov 13 '22 00:11

Charles Duffy