I took a break off application programming in November 2012 to perfect my skills in Linux System Programming.
The main difference between the two is;
Application programming aims to produce software which provides services to the user (e.g. Anansi Calcpad), whereas systems programming aims to produce software which provides services to the computer hardware (e.g. disk clean up).
Even if you think you're not a programmer, Linux has some features to make your life a bit easier.
Any time you have a repetitive task that involves entering Linux commands or changing the contents of a file, you should think about automating it with a program in linux. I installed an old version of Ubuntu 11.10 ( It’s a linux distribution and a stable build ) and started playing around with the terminal; doing some basic stuff like echoing the name of the terminal , writing simple addition programs , sleep , pwd and spent more time online reading about file permissions ( Read, Write , Execute ) , appending output file ,variables , shell scripting , process structure , for loops and many interesting stuffs.
The Bash shell is your main port of entry to Linux, since the shell interprets everything you enter on the command line before passing it along to the operating system for execution.
I fell in love with shell scripting because unlike Java you didn't need to assign data types
Int , float , string , char when declaring a variable and you do not need a terminator (semi – colon ; ) in most instances.
For example,in Java:
int $num1 = 70;
In shell scripting:
num1 = 20
Often, writing a shell script is much faster than writing the equivalent code in other programming languages like Java and Python.
The many advantages include easy program or file selection, quick start, and interactive debugging. A shell script can be used to provide sequencing and decision-making linkage around existing programs, and for moderately-sized scripts the absence of a compilation step is an advantage.
Interpretive running makes it easy to write debugging code into a script and rerun it to detect and fix bugs. Non-expert users can use scripting to tailor the behavior of programs, and shell scripting provides some limited scope for multiprocessing.
We will write a simple script that will allow us to let the bash sleep for a while, delete all the files that is starts with
STEP 1: Let’s create three files in the bash terminal
STEP 2: Let’s give all the three files all permissions rights for the user, group and others.
Chmod 777 klm*
NB: * stands for all files
To view all files with the date last edited or permission rights and details use this command:
(Long listing) and check if all files have all the rights.
STEP 3: We will now write a simple program in the VI Editor to sleep for 5 seconds and afterwards delete all files.
echo “ Your text here “
Final step is to execute this program in the main shell. To execute it use this simple command bash and the name of the file in the VI Editor.
You have now created a simple shell script that automates the process of putting the shell to sleep and deleting the files that start with the word KLM. With just these few lines of code you can easily build a simple program in Linux.These are screen grubs from the simple script we wrote above in the bash terminal and the VI Editor.
Now let’s write a little complex program. This program that will have 5 options.
echo "SELECT A NUMBER“
(1 FOR LOVE (2 FOR DRUGS (3 FOR SPORTS (4 FOR HEALTH
Each option will contain a text eg. Love : feel tender affection for somebody, so when a user chooses a number 1-5 it will display some text.
In the bash terminal you use the cat syntax to input append a text into a file:
cat > drugs
You will find the complete source code to a dummy program I wrote here on my github repository it contains a for loop and CASE conditions.
Unlike Java I did not have to import any special packages to allow the user to input text.
If you've ever written a simple console program ,word processor macro or a spreadsheet formula, you're a programmer.
By taking advantage of Linux's built-in programming features, you can automate repetitive tasks and build simple interactive applications without a degree in computer science.Send me a mail if you have any question or contribution iraindolf [at] gmail.com
"Software is like sex: it's better when it's free." -- Linus Torvalds
Image Credit: Blind Nomad