Find the answer to your Linux question:
Results 1 to 3 of 3
Hi All, I need to write a script, where shell can do the following: Lets suppose, I have a shell script "arun.sh" containing 2-3 lines (just below): a=$$ #echo "ARUN ...
  1. #1
    Linux Newbie Sangal-Arun's Avatar
    Join Date
    May 2006
    Location
    Gurgaon, India + Denver Colorado USA
    Posts
    101

    Lightbulb Dynamic Runtime - Comment handling BASH for Debugging purpose

    Hi All,

    I need to write a script, where shell can do the following:

    Lets suppose, I have a shell script "arun.sh" containing 2-3 lines (just below):
    a=$$
    #echo "ARUN IS TRYING TO SET DEBUG PARAMETER"
    echo $a

    NOTE: The above code is an example, showing hard coded '#' comment used at line no. 2. Means, we don't want to print this line.

    Now, what I want is that: Is it possible for BASH to recognize "#" (used for commenting) at run time(dynamically) and it will not print a line if it finds "#" in a variable (which I will place at first) and print whatever is there, if it finds that variable="" (BLANK). A snapshot of this is as below: (Here, I have just added a comment variable to store a "#" or blank "", this should be set by a user before calling the script or can be passed at run time as 1st argument to arun.sh script (In this case, I should use: comment_variable=$1).

    comment_variable=#

    a=$$
    $comment_variable echo "ARUN IS TRYING TO SET DEBUG PARAMETER"
    echo $$
    echo $a

    Now, I want the shell script to check (at run time), if $comment_variable is having '#' as its value, then it should not print the line:
    "ARUN IS TRYING TO SET DEBUG PARAMETER"

    ELSE it should treat that line just a simple echo statement and print it.

    *** NOTE *** I don't want to use if, else, fi for checking $comment_variable's value (especially in this script) or any other types of checks for doing this.

    I hope, I clarified what I want. If not, give me a shout at ak.sangal@interglobetechnologies.com

    /Arun Sangal
    Brgds,

    ARUN SANGAL
    SCM: 1- 720 251 9962
    Email: sangal.ak04@gmail.com
    Email: sangal_ak04@yahoo.com

  2. #2
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi, Arun Sangal.

    Perhaps this is similar to what you are looking for. Run it a few times interchanging the settings for variable debug:
    Code:
    #!/bin/sh
    
    # @(#)  s1      Demonstrate use of colon, :, as a null command.
    
    debug="echo"
    debug=":"
    
    i=0
    while [ $i -lt 5 ]
    do
            $debug "The value of i is $i"
            i=$(( i+1))
    done
    
    echo "The final value of i is $i."
    cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  3. #3
    Just Joined!
    Join Date
    Jun 2008
    Posts
    4
    Hi Arun. did it solve ur problem ? becoz i dont think this is wat u had asked for .., I am also looking for something similar.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...