while already in post #2 it was pointed out to you (and in various other posts in this thread) that this is not correct and suggested you use this instead:
Code:
if [ $# != 2 ]; then
usage
fi
Please have a good look at the suggestions and take your time experimenting. And then come back here once you tried all the suggestions...
I have tried using the above method as it was suggested before. There is no change in the result.. So here it is
Code:
function usage() {
if [ $# != 2 ]; then
echo
echo "*******************************************"
echo " !!! USAGE PARAMETERS !!! "
echo "*******************************************"
echo
echo
echo "USAGE:"
echo " " `basename $0`" <OPTION> <SERVICE_NAME> "
echo
echo " <SERVICE_NAME> = Enter the vaild SERVICE_NAME that exists in APPS DIR.
<-L | -l> = Searching from the LIVE LOGS.
<-A | -a> = Searching from the ARCHIVE LOGS."
echo
fi
}
usage
exit
Result ,
Code:
$ ./testxmlsearch.sh -a SERVICE_NAME
*******************************************
!!! USAGE PARAMETERS !!!
*******************************************
USAGE:
testxmlsearch.sh <OPTION> <SERVICE_NAME>
<SERVICE_NAME> = Enter the valid SERVICE_NAME that exists in APPS DIR.
<-L | -l> = Searching from the LIVE LOGS.
<-A | -a> = Searching from the ARCHIVE LOGS.
The above result is only valid when any of the input arguments are missing, but not in this scenario when the script has passed with valid arguments to search.
Thanks in advance, if can get a break through.
---------- Post updated at 07:48 AM ---------- Previous update was at 07:23 AM ----------
SCENARIO 1: Here is the Result when I changed the USAGE function as below
Code:
function usage() {
if [ $# != 2 ]; then
echo
echo "*******************************************"
echo " !!! USAGE PARAMETERS !!! "
echo "*******************************************"
echo
echo
echo "USAGE:"
echo " " `basename $0`" <OPTION> <SERVICE_NAME> "
echo
echo " <SERVICE_NAME> = Enter the vaild SERVICE_NAME that exists in APPS DIR.
<-L | -l> = Searching from the LIVE LOGS.
<-A | -a> = Searching from the ARCHIVE LOGS."
echo
fi
exit
}
This is a VALID OUTPUT when passing both (OPTION & SERVICE_NAME) the argument ---> 2 Arguments Passed for the script
Code:
$ ./testxmlsearch.sh -a SERVICE_NAME
***Found the service logging in APPS***
Change directory to path : /logs/production/Apps/logs is SUCCESSFULL
**********************************************************
My line: MsgID=414d51204450303141504420202020204c7e897a20374b16
**********************************************************
Search String not found in 1
**********************************************************
My line: MsgID=414d51204450303141504420202020204c7e897a20374b16
**********************************************************
Search String not found in 2
**********************************************************
My line: MsgID=414d51204450303141504420202020204c7e897a20374b16
**********************************************************
Search String not found in 3
**********************************************************
My line: MsgID=414d51204450303141504420202020204c7e897a20374b16
**********************************************************
Search String not found in 4
**********************************************************
My line: MsgID=414d51204450303141504420202020204c7e897a20374b16
**********************************************************
Search String not found in 5
BUT the result for any one argument is INVALID and still looping, giving NO PROMT ----> 1 Argument passed for the script
Instead it should throw the USAGE Parameters
Code:
$ ./testxmlsearch.sh -a
^C
$
SCENARIO 2: Here is the Result when I changed the USAGE function as below
Code:
function usage() {
if [ $# != 2 ]; then
echo
echo "*******************************************"
echo " !!! USAGE PARAMETERS !!! "
echo "*******************************************"
echo
echo
echo "USAGE:"
echo " " `basename $0`" <OPTION> <SERVICE_NAME> "
echo
echo " <SERVICE_NAME> = Enter the vaild SERVICE_NAME that exists in APPS DIR.
<-L | -l> = Searching from the LIVE LOGS.
<-A | -a> = Searching from the ARCHIVE LOGS."
echo
fi
}
usage
exit
This is a INVALID OUTPUT when passing both (OPTION & SERVICE_NAME) the argument ---> 2 Arguments are passed to script
Code:
$ ./testxmlsearch.sh -a SERVICE_NAME
*******************************************
!!! USAGE PARAMETERS !!!
*******************************************
USAGE:
testxmlsearch.sh <OPTION> <SERVICE_NAME>
<SERVICE_NAME> = Enter the vaild SERVICE_NAME that exists in APPS DIR.
<-L | -l> = Searching from the LIVE LOGS.
<-A | -a> = Searching from the ARCHIVE LOGS.
function usage() {
# THIS IS WRONG!
# This SHOULD NOT be in the function!
# Your memory is incorrect -- this never worked, or required weird workarounds to force it to work.
# $# refers to FUNCTION PARAMETERS inside a function, NOT SCRIPT PARAMETERS!
# Copy-paste the code in post 12 without modifying it! It will work!
# Repeat -- without modifying! It will work, I have verified this personally!
if [ $# != 2 ]; then
# ONLY this part should be in the function, only the echo statements.
echo
echo "*******************************************"
echo " !!! USAGE PARAMETERS !!! "
echo "*******************************************"
echo
echo
echo "USAGE:"
echo " " `basename $0`" <OPTION> <SERVICE_NAME> "
echo
echo " <SERVICE_NAME> = Enter the vaild SERVICE_NAME that exists in APPS DIR.
<-L | -l> = Searching from the LIVE LOGS.
<-A | -a> = Searching from the ARCHIVE LOGS."
echo
fi
}
usage
exit
if [ $# != 2 ]; then
function usage() {
echo
echo "*******************************************"
echo " !!! USAGE PARAMETERS !!! "
echo "*******************************************"
echo
echo
echo " " `basename $0`" <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."
echo
fi
}
usage
exit
Result after change even after closing all the functions
Code:
$ ./testxmlsearch.sh -a SERVICE_NAME
./testxmlsearch.sh: line 54: syntax error near unexpected token `fi'
./testxmlsearch.sh: line 54: ` fi'
$./testxmlsearch.sh -a
./testxmlsearch.sh: line 54: syntax error near unexpected token `fi'
./testxmlsearch.sh: line 54: ` fi'
---------- Post updated at 08:27 AM ---------- Previous update was at 08:20 AM ----------
Thanks for all . The script is Working really good now.
THE FINAL CHANGE IS HERE
Code:
if [ $# != 2 ]; then
function usage() {
echo
echo "*******************************************"
echo " !!! USAGE PARAMETERS !!! "
echo "*******************************************"
echo
echo
echo " " `basename $0`" <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."
echo
}
usage
exit
fi
########### Subroutines
function usage() {
echo
echo "*******************************************"
echo " !!! USAGE PARAMETERS !!! "
echo "*******************************************"
echo
echo
echo " " `basename $0`" <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."
echo
}
########## MAIN
if [ $# != 2 ]; then
usage
exit
fi
Slight variation to post #20 because `basename $0` won't give the desired result in function.
Code:
### Beginning ============
SCRIPT_NAME="`basename $0`"
########### Subroutines
function usage() {
echo
echo "*******************************************"
echo " !!! USAGE PARAMETERS !!! "
echo "*******************************************"
echo
echo
echo " ${SCRIPT_NAME} <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."
echo
}
########## MAIN
if [ $# != 2 ]; then
usage
exit
fi
Notice that the function "usage" is only executed when we don't provide exactly two parameters.
All,
I have a basic buzz program written in python with return function. If i change return with print,it works fine but i want to know whats wrong with return statement.Can anyone help me whats wrong with this
#!/usr/bin/python
def div4and6(s,e):
for i in range(s,e+1):
if... (5 Replies)
hi whats wrong in below??
CHECK=M10;
if ;
then
echo "hello hi";
else
echo "how are u hello hi";
fi
I am getting error as
./test.sh: line 2: '
./test.sh: line 2: M10: command not found
./test.sh: line 2: M10: command not found
./test.sh: line 2: M10: command not found (8 Replies)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
ls -ld htdocs
drwxr-x--- 3 root root 8192 2006-11-19 10:41 htdocs
How would a host administrator... (1 Reply)
can anyone tell me why this code doesn't work how its supposed to, its the hangman game but it doesn't play how its supposed to
#!/bin/bash
NoAttempts="0"
livesgiven="5"
LivesRemain=$livesgiven
LettersAttempted=""
wordfile=words
numwords=0
function menu()
{
clear
cat << menu... (1 Reply)
if
then
if
then
echo "fst argument is $1 "
else
if
then
"fst argument is $1"
fi
fi
fi
Can anyone tell me. My requirement is tht pass a string ..
Check whether it contains "-". If yes then check if it... (1 Reply)
#! /bin/bash
USAGE=" | ]
if
then
echo "$USAGE"
exit 1
fi
while getopts lb: OPTION
do
case $(OPTION)in
a) echo Hi there!
exit 2;;
b) echo hello
o) OARG=$OPTARG;;
\?)echo "$USAGE" ;;
exit 2;;
esac
done
shift `expr... (1 Reply)
#! /bin/bash
head -5 $1
echo "remove $1 ?"
read answer
if
then
echo invalid answer
elif
rm $1
echo "$1 is deleted"
elif
then
echo file is not deleted
else
echo "invalid answer"
fi
What i really want this to do is to ask to delete the file or not..it says something wrong... (1 Reply)
First of all im using Bash, on a Debian-based machine. I tried to write a function that if the ls program found listed more than 25 lines I would automaticly use "ls | less". Its on another computer but if I recall it looked something like this...
Note: some code may look strange because im on... (4 Replies)