Parameter Passing problem | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Parameter Passing problem

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-22-2009
Raamc Raamc is offline
Registered User
 
Join Date: Sep 2007
Last Activity: 6 April 2012, 10:35 PM EDT
Posts: 55
Thanks: 2
Thanked 0 Times in 0 Posts
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.
Sponsored Links
    #2  
Old 07-22-2009
kshji's Avatar
kshji kshji is offline
Registered User
 
Join Date: Jun 2009
Last Activity: 26 February 2014, 5:44 AM EST
Location: Finland
Posts: 602
Thanks: 0
Thanked 50 Times in 49 Posts
You are using ksh and call sh ?
If you like to use ksh, then

Code:
ksh script arg1 arg2

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

Code:
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"

Sponsored Links
    #3  
Old 07-23-2009
Raamc Raamc is offline
Registered User
 
Join Date: Sep 2007
Last Activity: 6 April 2012, 10:35 PM EDT
Posts: 55
Thanks: 2
Thanked 0 Times in 0 Posts
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?
    #4  
Old 07-23-2009
ryandegreat25 ryandegreat25 is offline
Registered User
 
Join Date: Jul 2009
Last Activity: 27 November 2013, 3:15 AM EST
Posts: 286
Thanks: 16
Thanked 3 Times in 3 Posts
script looks ok to me. can you try passing 3 arguments and let us see.
Sponsored Links
    #5  
Old 07-23-2009
kshji's Avatar
kshji kshji is offline
Registered User
 
Join Date: Jun 2009
Last Activity: 26 February 2014, 5:44 AM EST
Location: Finland
Posts: 602
Thanks: 0
Thanked 50 Times in 49 Posts
Publish your current version of your scripts. Also the command line, how you call your script. Easier to say what problem you have.
Sponsored Links
    #6  
Old 07-23-2009
Raamc Raamc is offline
Registered User
 
Join Date: Sep 2007
Last Activity: 6 April 2012, 10:35 PM EDT
Posts: 55
Thanks: 2
Thanked 0 Times in 0 Posts
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.
Sponsored Links
    #7  
Old 07-23-2009
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
 
Join Date: Apr 2004
Last Activity: 20 January 2014, 5:51 AM EST
Location: Bordeaux, France
Posts: 1,711
Thanks: 2
Thanked 61 Times in 57 Posts
Try to replace

Code:
set -v on
set -x on

set -v off
set -x off

by
Code:
set -v
set -x

set +v
set +x

Jean-Pierre
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Passing asterisk As A Parameter indiansoil Shell Programming and Scripting 8 07-19-2008 10:27 AM
Passing Parameter in SED command dsrookie UNIX for Dummies Questions & Answers 2 06-09-2008 01:25 AM
wrong parameter passing! malle Shell Programming and Scripting 2 02-03-2007 06:21 AM
Passing parameter to makefile? manju_p Programming 3 11-07-2006 03:39 AM
parameter passing kekanap Shell Programming and Scripting 8 07-20-2006 09:58 AM



All times are GMT -4. The time now is 01:59 AM.