How to create your own executable in Ubuntu! using shell script

I have been using a small script written myself to enable and disable my Synaptic touch-pad in my laptop for the last few months and today I thought I should covert this to a linux executable and just use this script same as other terminal commands.. Finaly, I got it done. This is how I did it 🙂

Step 1

Installed the “shc package” to convert my shall script to executable

1
2
3
4
5
6
$ sudo vi /etc/apt/sources.list
#and add the following line in to the list 
deb http://ubuntu.mirror.cambrium.nl/ubuntu/ hardy main universe
# and then execute 
$ sudo apt-get update
$ sudo apt-get install shc

Step 2

Here is my shell script
Download touchpad_enable.sh from here

This is how I have been using it to enable and disable my touch-pad

1
2
$ ./touchpad_enable.sh 0 # 0 for disable touch-pad 
$ ./touchpad_enable.sh 1 # 1 for enable touch-pad

Step 3

Convert shell .sh to executable

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ shc shc -vrTf touchpad_enable.sh
 
# here is the output 
 
priyantha@priyantha-laptop:~$ shc shc -vrTf touchpad_enable.sh
shc shll=bash
shc [-i]=-c
shc [-x]=exec '%s' "$@"
shc [-l]=
shc opts=
shc: cc  touchpad_enable.sh.x.c -o touchpad_enable.sh.x
touchpad_enable.sh.x.c: In function 'chkenv':
touchpad_enable.sh.x.c:221:10: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
shc: strip touchpad_enable.sh.x
shc: chmod go-r touchpad_enable.sh.x

Step 4

Move executable file (touchpad_enable.sh.x) to /usr/local/bin/

1
$ sudo mv touchpad_enable.sh.x /usr/local/bin/touchpad_enable

Finally! :), I can execute my script from anywhere in the terminal as below.

1
2
3
$ touchpad_enable 0
or
$ touchpad_enable 1

1 thought on “How to create your own executable in Ubuntu! using shell script”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.