How to Convert Your Shell Script to Binary

How to create a binary file of your Shell Scripting.

This article will help you create a binary file of your Shell Scripting, so that no one can see the source code of your script and we can use it as a command. To create a binary file from a script, we use the SHC compiler .


shc, a Shell Script compiler, produces the source code in C. The generated source code is then compiled and linked to produce a separate binary executable.

The compiled binary will continue to be dependent on the shell specified in the first line of the shell code (ie, shebang) (ie #!/bin/sh), so shc does not create completely independent binaries.

shc itself is not a compiler like gcc, it encodes and encrypts a shell script and generates the C source code with the added expiration feature. It then uses the system compiler to compile a separate binary that behaves exactly like the original script. After execution, the compiled binary will decrypt and execute the code with the shell -c option.


In Gentoo and similar, use the portage that shc is already available on the tree:

emerge dev-util/shc

For other distributions, for example derived from APT, first install the necessary dependencies:

sudo apt-get install libc6-dev # Debian, Ubuntu, Mint, ...
sudo yum install glibc-devel # RHEL, CentOS, Fedora, ...

Then download the package, decompress and compile the code:

cd shc-*
sudo make install


Create a test file to see how it works: vim


echo -e "The first 3 characters of each location file / directory are:\n"
for i in *; do
	echo "$i" | cut -c 1-3 | tr '\n' '\ '

Then use shc to transform it into binary:

shc -f -o binary

And just run the program: ./binary

If you try to see the contents of the binary file, you will see everything encoded, example: cat binary


Para mais informações e opções via linha de comando, utilize a ajuda e o manual:

shc --help
man shc

Official page shc:

Thanks for reading!

bash shellscript clang