Linux Shell Programming

I had a little bit experience in Liunx Shell Progrmming through my undergraduate course work. At that time we used to create simple shell script with using only cp, grep, head, tail, mv, rm command of Shell Programming. I had never encounter with the problem of script writing for which I need to debug the script in undergraduate course. While working with some problems of shell programing in Exling LLC, I encounterd a buggy script for which I need to debug a script. At that time, I learned some features of debugging a script. I had gained a pretty well idea on debugging a script. It is much easier and essential feature of shell scripting. It solves many problems for which people may have to wait and work for many days.

I am including the buggy script first to show the  debugging features here:

#!/bin/bash
# a.sh

# This is a buggy script.
# Where, oh where is the error?

a=37

if [$a -gt 27 ]
then
  echo $a
fi 

exit 0

There are two ways to debug a script file in Shell Programing. These two ways are:
     1.  sh -v script.sh       #Display shell input lines as they are read   
     3.  sh -x script.sh       #Display commands and their arguments as they are executed

When  I used the first method I couldn't understand anything of the error in the script. Then I used the second method I can visualize the exact scenerio. Here is the output of the debugging command:

+ a=37
+ '[37' -gt 27 ']'
a.sh: line 4: [37: command not found
+ exit 0

The bug removed program is as follows:
#!/bin/bash
# a.sh

# This is a buggy script fixed.
# The Error is near the third bracket of before $a in the " if " condition. There should be a space.

a=37

if [ $a -gt 27 ]
then
  echo $a
fi 

exit 0

Comments

  1. Hi sis, visit my blog to know about me if you want. Here, I just want to know what is the difference between a Script Language and A Programming Language? Why we have Java Script and Java programming Language differently? I actually just want to know what it is a script and how it differs from a programming language.

    This is first time I am visiting your blog and questioned you. I hope you did not mind. I am studying CSE.

    ReplyDelete
  2. Hello Tanmay,
    I visited your blog on computer programming. It is awesome. I think programming languages both for our separate needs. We use to make software by using Java programming language, but we cannot make online web portal or online solutions using java programming languages. We need to use different scripting languages for that. Java has a special language for web programming namely J2EE. J2EE uses xml script for online programming feature. Scripting languages are compiled and executed in run-time. I think this is enough for your query. If you want to know more, feel free to contact here.

    ReplyDelete
  3. Well sis, that helped. So a scripting language differs from programming language in a way that programs based on scripting language get compiled each time on execution, whereas programs based on programming languages get compiled once. Is it so?

    Thanks for visiting my blog and calling it "Awesome". I offered you that as I don't introduced me on the first comment. Though my blog is on Computer Programming it holds many other things like my poems, games reviews, movie reviews etc. Hope you have liked them.

    ReplyDelete

Post a Comment

Popular posts from this blog

Puzzle

Importing Java Library

Examples on mod_rewrite