If we want to obfuscate what the script is doing we can compile it to binary using
shc. As this is often not installed, we can add it using
brew on mac or
apt-get for Debian based Linux systems. Alternatively, we can install it from here (the github repository) and running
Start with your bash script
#!/bin/bashecho "How are you $1?"
Building the compiled script
To build the files we can run
shc -f scriptname.sh
This creates a
scriptname.sh.x which is our compiled executable and
scriptname.sh.x.c which is the c transpiled file that this is created from.
We can now rename our file to something along the lines of
mv scriptname.sh.x scriptname
Note: If we get some errors, these can often be ignored if the output file is created and functions as intended.
Testing the compiled version
The last thing we have left to do is to make sure that everything went well in the process. We start by making the compiled file executable with
chmod a+x scriptname . Next we test its output — In our case running:
“How are you Medium?” to screen.