Shell Scripting with Bash- Part1 - wiki4techi

Shell Scripting with Bash- Part1



The Origin of Bash-

A shell is also a a program that open a typical black coloured window, through which you can run operating system commands. This kind of interface may confuse new users who have always seen desktop as full GUI with icons and touch screen.

                   The first Unix shell was the developed by Steven R. Bourne in 1974 for the Seventh Edition of Unix. Called the Bourne shell (or simply sh) in honour of its creator, it set the standard for Unix shells, including the default dollar sign ( $ ) prompt common to most shells.

                 In early days of development, (desktop without UI) users needed to type the same commands over and over again.Writing a pro gram to repeat their commands required a high-level language like C. Same like batch file in windows…, it was useful to compose a list of commands, which through shell window were executed on computer. This was further extended along with simple decisions and loops. Those are called shell scripts. These shell scripts could run commands and determine whether they succeeded or failed, taking appropriate action, without resorting to a different language. When commands are combined in new ways in a script, a script conceptually becomes a new command. Scripts can customize and extend operating systems. Designed to be as small and as open as possible. Even arithmetic was performed by other programs outside of the shell.This slowed the shell, but speed was not an important factor when the shell spent most of its time waiting on other programs or on the user. To the shell’s advantage, if a user needed new or better capabilities, the user could write additional scripts to provide those additional capabilities.

            Many competitive shells began to appear, offering improvements in speed and capabilities. Like csh, a shell loosely based on the C language, and the Korn shell (ksh), an improved Bourne shell developed by David G. Korn. Shell designers incorporated commands into the shell for better speed and portability and to make the shells easier to work with. Successful features were freely copied between shells as they matured.


An enhanced version of the Bourne shell was developed as part of the GNU project used by the Linux operating system.The shell was called Bash (for the pun “BourneIntroduction Again Shell”).This shell was compatible with the original shell created by Steven R. Bourne, but included many enhancements. It was also compliant with the POSIX standard for shells.

Program vs Shell Script:

A script as good as a program but there is no formal definition for what constitutes a script. It is a type of simple program, and scripts and programs share many features in common. As shells matured, they gained many features that you might not expect to find in a program designed to schedule commands. Most shells, including Bash, can perform bit manipulation, string processing, and TCP/IP connections.They have typed variables, built-in commands, and user-defined functions. The distinction between shells and programming languages has become blurred.

           In general, there are two key differences between shell scripts and more complex programs typically developed by programming languages like C,C++,C#,Java.

1. Shells are designed to handle short, simple tasks.They lack the rigid structure and semantic checking of a high-level language.

2. Shell scripts are slow. Although most shells perform some kind of pre-processing to speed up execution, they still interpret and carry out one line at time. High-level languages are faster because they compile to machine code (executable) to gain the best performance.

        When tackling any programming problem, it’s essential to choose the right tool for the job. The shell is quick and dirty and for small tasks, where as formal high level languages are for large, structured development.


Getting hands-on

Bash is available in most of the standard Linux desktops and servers. All the scripts mentioned in this training sessions are tested on Ubuntu 14.04 latest distribution. You should be able to run them on similar distributions like Suse, Mandrek, slackware, Redhat etc.

On your desktop, you can either go to menu and open “Terminal” or another quick way is to press key combination Ctrl+Alt+ T. This will open the terminal window as shown.


It automatically chooses its own background/foreground color, and window size. Of course you can change it the way you want to.

           On your Linux box, each file is identified by a name, and the allowed names are determined by the file system. For practicality, the names seldom exceed 32 characters and usually consist of lowercase characters, underscores, minus signs, and periods. Spaces and punctuation symbols, for example, are permitted, but can cause problems in shell scripts that do not expect them.

Filenames do not require a suffix to identify their contents, but they are often used to avoid confusion about what data is contained in files. Some common suffix codes include:

  • .sh —A Bash shell script

  • .txt —A generic text file

  • .log —A log file

  • .html —A HTML Web page

  • .tgz (or .tar.gz )—Compressed file archive

Commands usually have no suffix.


Before we script, Some more basics:

Bash Keywords

A keyword is a word or symbol that has a special meaning to a computer language. The following symbols and words have special meanings to Bash when they are unquoted and the first word of a command.



Unlike most computer languages, Bash allows keywords to be used as variable names even though this can make scripts difficult to read. To keep scripts understandable, key words should not be used for variable names.

Command Basics

To execute a command, you have to type ir and press “enter” to execute that command.

The date command prints the current date and time on the screen.

The screen-shot shows the simple date command, sate command with upper-case… and date command with arguments.




As you could see, the linux shell discriminates between upper-case and lower-case (unlike Windows terminal). Secondly arguments also alter the output of command.

For more information about any command you can always type: man “command”

to retrieve the man (manual) page for that command.




Anand Khatri

You may also like...

8 Responses

  1. Thanks, I have recently been searching for details about this subject for ages and yours is the best I’ve found so far.

  2. Woah! I’m really enjoying the template/theme of this site. It’s simple, yet effective. A lot of times it’s difficult to get that “perfect balance” between usability and visual appeal. I must say you’ve done a excellent job with this. In addition, the blog loads extremely quick for me on Chrome. Exceptional Blog!

  3. Thanks for one’s marvelous posting! I seriously enjoyed reading it, you happen to be a great author.I will be sure to bookmark your blog and will often come back from now on. I want to encourage you continue your great writing, have a nice holiday weekend!
    Top vente de Adidas Noir Hommes Training Porsche

  4. First of all I want to say superb blog! I had a quick question which I’d like to ask if you do not mind. I was interested to find out how you center yourself and clear your thoughts before writing. I’ve had a tough time clearing my thoughts in getting my thoughts out there. I truly do enjoy writing but it just seems like the first 10 to 15 minutes are usually lost simply just trying to figure out how to begin. Any suggestions or hints? Thank you!|掲示板}
    Faible coût New Balance Training

  5. It’s a shame you don’t have a donate button! I’d without a doubt donate to this excellent blog! I suppose for now i’ll settle for book-marking and adding your RSS feed to my Google account. I look forward to new updates and will talk about this site with my Facebook group. Talk soon!
    Bon Service Adidas Training Hommes Climacool Noir

  6. Wonderful blog! I found it while surfing around on Yahoo News. Do you have any tips on how to get listed in Yahoo News? I’ve been trying for a while but I never seem to get there! Many thanks
    Günstige preise Blau Orange Herren Running

  7. I’m truly enjoying the design and layout of your website. It’s a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did you hire out a designer to create your theme? Superb work!
    Vérifiez Adidas Trainingées-Adidas-Training-t-3570_2378.html

Leave a Reply

Optimization WordPress Plugins & Solutions by W3 EDGE