Bug in Function Call


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bug in Function Call
# 1  
Old 09-29-2010
Bug in Function Call

Can anybody tell me where is the bug in this below mentioned function call.

Code:
#The String Search File

myString="${LOCATION}/config/stringFile.txt"

# Functional Usage

function usage() {

        if [ "$#" != 2 ]; then
        echo "************************************************************"
        echo "          CHECK USAGE FOR CORRECT PARAMETERS                "
        echo "************************************************************"
        echo
        echo "  USAGE:   "
        echo "  $BASENAME  <OPTION> <SERVICE_NAME>  "
        echo
        echo "  <SERVICE_NAME> = Enter the vaild SERVICE_NAME that exists in 76S DIR.
  <-L | -l>      = Searching from the LIVE LOGS.
  <-A | -a>      = Searching from the ARCHIVE LOGS."
        else
        echo
        echo "***********************************************************************************************"
        echo "          Searching for the $srvname XML in Request                                             "
        echo "***********************************************************************************************"
        echo
        fi
        exit
        }

Above function not getting me the prompt or the USAGE shown above .

Quote:

$ ./xmlSearch.sh -l
^C
$
# 2  
Old 09-29-2010
You declare the code in a function, but I don't see that you're actually using the function anywhere. Functions don't call themselves, you call them like programs.

"$#" inside a function refers to the function's own arguments anyway, not the script's commandline parameters. I think what you must have meant to do is to have the code outside any function, or at least, have the comparisons outside any function.
# 3  
Old 09-29-2010
Do i need to call this function in CASE statement, if Yes ? How should i call it ?
Since there are 2 input parameters are required, if anyone Input Parameter missed, it should throw out an USAGE.

Instead using this
Code:
 if [ "$#" != 2 ]; then

can i USE this
Code:
 [ "$1" != 0 ] || [ "$2" != 0]; then

# 4  
Old 09-29-2010
As I just said, the "usage" code looks nearly correct (maybe replace != with -ne), but shouldn't be in a function at all. Functions don't call themselves, and the comparisons don't check what you think they do when in a function either.
# 5  
Old 09-29-2010
I expelled that function and retained the loop, and also changed != to -ne.

It worked well and also thrown out the USAGE, which actually im deserving. BUT
this has changed the other way, where it shouldnt throw the USAGE, instead it should extract the result for which the script was built.

Below are the output with changes.

Code:
VALID ERROR OUTPUT 

$ ./xmlSearch.sh -l
************************************************************
          CHECK USAGE FOR CORRECT PARAMETERS
************************************************************

  USAGE:
  xmlSearch.sh  <OPTION> <SERVICE_NAME>

  <SERVICE_NAME> = Enter the vaild SERVICE_NAME that exists in DIR.
  <-L | -l>      = Searching from the LIVE LOGS.
  <-A | -a>      = Searching from the ARCHIVE LOGS.


Invalid RESPONSE from the SCRIPT, when used with all INPUT PARAMETER

Code:
Invalid Result :(

$ ./xmlSearch.sh -a devicemanagementservice
************************************************************
          CHECK USAGE FOR CORRECT PARAMETERS
************************************************************

  USAGE:
  xmlSearch.sh  <OPTION> <SERVICE_NAME>

  <SERVICE_NAME> = Enter the vaild SERVICE_NAME that exists in DIR.
  <-L | -l>      = Searching from the LIVE LOGS.
  <-A | -a>      = Searching from the ARCHIVE LOGS.

Guide me where im going WRONG
# 6  
Old 10-02-2010
It works fine for me. Post your modified code.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. What is on Your Mind?

Small bug in the Quick Editor function in postbit

Hey, There was a small bug in the Quick Editor function in postbit, but I fixed it (basically a double quote was missing from an element id): <div id="post_message_$post" class="neo-message-area">$post</div> Was <div id="post_message_$post class="neo-message-area">$post</div> Should... (1 Reply)
Discussion started by: Neo
1 Replies

2. Programming

Tweaked getpass() function gives an untraceable bug

I have customized the getpass() as follows: char* my_getpass(const char* str) { struct termios oflags, nflags; static char passwd; /* disabling echo */ tcgetattr(fileno(stdin), &oflags); nflags = oflags; nflags.c_lflag &= ~ECHO; nflags.c_lflag |= ECHONL; ... (3 Replies)
Discussion started by: royalibrahim
3 Replies

3. Shell Programming and Scripting

Sort function UNIX bug ???

Hello there i have a funny behiavor of the sort fonction, i try it out on different Solaris machine and i have the same issue. So i would like to see if there is a rationel explanation here is some data in a file:test.txt ,Test,RSD,RSD_Asset ,Test,RSD,RSD_Credit ,Test,RSD,RSD_Liab... (3 Replies)
Discussion started by: kykyboss
3 Replies

4. Shell Programming and Scripting

How to Call a Function

Hi I have created a function in a Shell Script test.sh function fnTest() { echo "My first Method } I have called this function in my test.sh cat abc.txt | grep "test" echo " test" fnTest But while running the shell script i got the following error: ... (2 Replies)
Discussion started by: nanthagopal
2 Replies

5. Shell Programming and Scripting

After exit from function it should not call other function

Below is my script that is function properly per my conditions but I am facing one problem here that is when one function fails then Iy should not check other functions but it calls the other function too So anyone can help me how could i achieve this? iNOUT i AM GIVING TO THE... (1 Reply)
Discussion started by: rohit22hamirpur
1 Replies

6. Infrastructure Monitoring

diffrence between method call and function call in perl

Hello, I have a problem with package and name space. require "/Mehran/DSGateEngineLib/general.pl"; use strict; sub System_Status_Main_Service_Status_Intrusion_Prevention { my %idpstatus; my @result; &General_ReadHash("/var/dsg/idp/settings",\%idpstatus); #print... (4 Replies)
Discussion started by: Zaxon
4 Replies

7. Shell Programming and Scripting

Function Call

Hi, I have a string corresponding to a function. How I can call that function without if statement? Thanks in advance. (4 Replies)
Discussion started by: Zaxon
4 Replies

8. Shell Programming and Scripting

bash-function with array acting bizarre, bug?

Hello, basically what this script is supposed to do is showing a list of hosts that is given a number, that you will be able to choose from a list. A check is made to verify that the chosen number is within the array and this is where things go bad and I don't know why, bizarre. I've spent... (5 Replies)
Discussion started by: gand
5 Replies

9. Shell Programming and Scripting

Function Bug in script - need help

My script is erroring with: testtapemgr.sh: FTP_RETURNS: not found I cannot see what I am doing wrong..when it calls that function from the Volume returns function and says taht FTP_RETURNS is not found and exits out of the script. What am I not seeing here? #### Return Volume Function ... (4 Replies)
Discussion started by: gzs553
4 Replies

10. Shell Programming and Scripting

function call

can I call a function in bash script just as in C++ while do function() done function() thanks, Steffen (3 Replies)
Discussion started by: forever_49ers
3 Replies
Login or Register to Ask a Question