How to convert shell script in to binary executable

How to convert shell script in to binary executable

Introduction –

Some time you want your shell script to be binary executable. You can do this by using the tool called Shell script compiler (shc).
shc
creates a stripped binary executable version of the shell script specified with -f on the command line. There is no speed increase from using shc.
Its main purpose is to prevent your shell scripts from being easily modified or inspected. shc can wrap scripts written for any shell.

1] How to install shc on Ubuntu/Debian system –

root@arunbagul:~# apt-get install shc
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following NEW packages will be installed:
shc
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 19.7kB of archives.
After unpacking 90.1kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com gutsy/universe shc 3.8.6-2 [19.7kB]
Fetched 19.7kB in 1s (14.8kB/s)
Selecting previously deselected package shc.
(Reading database … 88932 files and directories currently installed.)
Unpacking shc (from …/archives/shc_3.8.6-2_i386.deb) …
Setting up shc (3.8.6-2) …

root@arunbagul:~#

2] Sample shell script –

root@arunbagul:~# vim myscript.sh
root@arunbagul:~# cat myscript.sh
#! /bin/bash

echo -n “Welcome to shell script…”
echo -e “\n——————————–”
echo -n “Enter the number: ”
read num1

echo -n “Enter the number: ”
read num2

sum=$(expr $num1 + $num2)

echo -n “Sum to $num1 and $num2 = $sum”

echo -e “\ndone.”
root@arunbagul:~# chmod 755 myscript.sh
root@arunbagul:~#

root@arunbagul:~# ./myscript.sh
Welcome to shell script…
——————————–
Enter the number: 40
Enter the number: 50
Sum to 40 and 50 = 90
done.

root@arunbagul:~#

3] Steps to convert shell script to binary executable-

root@arunbagul:~# pwd
/root
root@arunbagul:~# ls
myscript.sh
root@arunbagul:~# shc -r -f myscript.sh

root@arunbagul:~# ls

** check in current working directory the binary file of you shell is created. You can deploy this script on any system (linux/Unix) for that you need to mention the options “-r” as shown in above command. please read shc man pages for more details.

Thank you,
Arun Bagul

Similar Posts:

Leave a Reply

Your email address will not be published.