Parameter Passing problem

Hi All,

I developed a KSH script which will accept two parameters as input. These two parameters are some directories paths.

In the script i am validating the number of paramaters it received as below
#--------------------------------------
# Check Command line arguments
#--------------------------------------
if [ ${#} -ne 2 ]
then
echo " ${NOW} ${ScrName} : Invalid Parameter list..."
echo " ${NOW} ${ScrName} : Script needs TWO parameters"
echo " ${NOW} ${ScrName} : Param1--Input file path"
echo " ${NOW} ${ScrName} : Param2--Output file path"
exit 1
fi

and i am calling my script as
sh Script Name /home/raamch/work/infile /home/raamch/work/infile

script is giving the error as
+ [ 1 -ne 2 ]
+ echo Wed Jul 22 04:42:27 CDT 2009 SELUPDFLE.sh : Invalid Parameter list...
Wed Jul 22 04:42:27 CDT 2009 SELUPDFLE.sh : Invalid Parameter list...
+ echo Wed Jul 22 04:42:27 CDT 2009 SELUPDFLE.sh : Script needs TWO parameters
Wed Jul 22 04:42:27 CDT 2009 SELUPDFLE.sh : Script needs TWO parameters
+ echo Wed Jul 22 04:42:27 CDT 2009 SELUPDFLE.sh : Param1--Input file path
Wed Jul 22 04:42:27 CDT 2009 SELUPDFLE.sh : Param1--Input file path
+ echo Wed Jul 22 04:42:27 CDT 2009 SELUPDFLE.sh : Param2--Output file path
Wed Jul 22 04:42:27 CDT 2009 SELUPDFLE.sh : Param2--Output file path
+ exit 1

Even i tried the script calling as below
scriptname "path1" "path2"
scriptname "path1","path2"
scriptname 'path1' 'path2'

But no use.
script is not accepting the two parameters.

Please help me on how to pass directory paths as parameters to the KSH script.

You are using ksh and call sh ?
If you like to use ksh, then

ksh script arg1 arg2

Your code works fine with every posix compatible sh, also with bsh.
I add some test echo:

if [ $# -ne 2 ]
then
 echo "$# , $*"
 echo " ${NOW} ${ScrName} : Invalid Parameter list..."
 echo " ${NOW} ${ScrName} : Script needs TWO parameters"
 echo " ${NOW} ${ScrName} : Param1--Input file path"
 echo " ${NOW} ${ScrName} : Param2--Output file path"
 exit 1
fi
echo "ok $1 and $2"

My Shell is BASH.
If i issue echo $SHELL, it is giving as bash.

Then i called the script witk KSH as ksh script.sh. Even after also it is giving the same problem(same error messages).

Can any one please help?

script looks ok to me. can you try passing 3 arguments and let us see.

Publish your current version of your scripts. Also the command line, how you call your script. Easier to say what problem you have.

Total script as below

#!/usr/bin/ksh
#####################################
# Starting the Main Script
#####################################
set -v on
set -x on
ScrName=`basename ${0}`
NOW=`date`
echo ${1}
echo ${2}
#
#-------------------------------------
# Routine for ERROR HANDLING
#-------------------------------------
#error_handle ()
#{
#echo "----------------------------------------->"
#echo "${NOW} ${ScrName} Error Handling...!"
#echo "----------------------------------------->"
#echo
#echo " ERROR Occured while ${1}"
#echo " EXIT from the program ......!"
#exit 1
#}
#--------------------------------------
# Check Command line arguments
#--------------------------------------
if [ $# -ne 2 ]
then
echo " ${NOW} ${ScrName} : Invalid Parameter list..."
echo " ${NOW} ${ScrName} : Script needs TWO parameters"
echo " ${NOW} ${ScrName} : Param1--Input file path"
echo " ${NOW} ${ScrName} : Param2--Output file path"
exit 1
fi

#--------------------------------------
# Get Log Directory
# and populate Log variables
#--------------------------------------
LogDate=`date "+%Y%m%d"`
LogDiry="${2}"
LogFile="${LogDiry}/SELUPD_${LogDate}.log"
#--------------------------------------
# Automatically Redirect STDOUT and STDERR to log file
#--------------------------------------
exec >${LogFile}
exec 2>${LogFile}

//////some logic
done
set -v off
set -x off
exit 0
#####END OF THE SCRIPT##########

i am calling the script as
sh script_name /home/user/work/infile /home/user/work/outfile

even i tried with the following calls
ksh script_name /home/user/work/infile /home/user/work/outfile
script_name /home/user/work/infile /home/user/work/outfile
./script_name /home/user/work/infile /home/user/work/outfile

but no use.

if i issue the command , echo $SHELL, it is giving the output as /usr/bin/bash.

I tried to login into ksh by issuing /usr/bin/ksh and called the script, but no use.

Try to replace

set -v on
set -x on

set -v off
set -x off

by

set -v
set -x

set +v
set +x

Jean-Pierre

For me, the "set -v" is the problem. Removing that the script works.

With -v

 > ./TestScr /home/user/work/infile /home/user/work/outfile
#set -x on
ScrName=`basename ${0}`
NOW=`date`
echo ${1}
on
echo ${2}

if [ $# -ne 2 ]
then
echo " ${NOW} ${ScrName} : Invalid Parameter list..."
echo " ${NOW} ${ScrName} : Script needs TWO parameters"
echo " ${NOW} ${ScrName} : Param1--Input file path"
echo " ${NOW} ${ScrName} : Param2--Output file path"
exit 1
fi
 Thu Jul 23 10:23:07 DFT 2009 T : Invalid Parameter list...
 Thu Jul 23 10:23:07 DFT 2009 T : Script needs TWO parameters
 Thu Jul 23 10:23:07 DFT 2009 T : Param1--Input file path
 Thu Jul 23 10:23:07 DFT 2009 T : Param2--Output file path

> echo $?
1

Without -v:

> ./TestScr /home/user/work/infile /home/user/work/outfile
/home/user/work/infile
/home/user/work/outfile
OK

> echo $?
0

Thanks Jean Pierre,

It is working. Thanks for your help.

I really appreciate all your help.