How to pass two word parameter

Hi,
How to pass parameter to run folloing script?

#parameters are div, dept, style
U run_convert_pdm.ksh Mens 44 7542
U run_convert_pdm.ksh "Mens Knit" 44 7541
 

The first command works fine but the second needs to have two words together , it does not work even if
I have used double quotes and single quotes.

Thanks
Sandy

We need to see what the code (run_convert_pdm.ksh ) does with the parameter.
Please post that section of the code.

What do you mean by 'does not work?'. Can you give us sample bad and good output please?

Double quotes work. If they don't, something is splitting them later. Show the code of the script.

Thanks for reply.

$ORACLE_HOME/bin/sqlplus ${USER}/${PASSWD}@${SID} >>./run_convert_pdm_${DEPT}.log <<EOC
whenever sqlerror exit 1
execute CNVT_SUMMARY('${DIV}','${DEPT}','${STYLE}');
EOC

this is error when ran using double quotes

**ERROR** with UNIX cmd/script [run_convert_pdm.ksh]

That cannot be the entire script. It doesn't use positional parameters at all. Please show the entire script.

You nearly got code tags to work. :slight_smile: They don't use {} though. It's actually

```text
stuff
```

without the extra spaces in the tags.

Sorry about that , please find the entire script

#!/usr/bin/ksh
# run_convert_pdm.ksh
#
USER=$1; export USER
PASSWD=$2; export PASSWD
SID=$3; export SID
PDM_DB=$4; export PDM_DB
OWNER=$5; export OWNER
DIV=$6; export DIV
DEPT=$7; export DEPT
STYLE=$8; export STYLE
if [ -z "$8" ]; then
echo " **ERROR** $0 - 8 arguments not provided!"
echo " Usage: $0 userid, password, database, pdm db link, owner, div, dept, style"
exit 1 # failure
fi
rm ./run_convert_pdm_${DEPT}.log
echo "**************** $(date +%c) Summary ${DEPT} ****************" >> ./run_convert_pdm_${DEPT}.log
$ORACLE_HOME/bin/sqlplus ${USER}/${PASSWD}@${SID} >>./run_convert_pdm_${DEPT}.log <<EOC
whenever sqlerror exit 1
execute CNVT_TP_SUMMARY('${PDM_DB}', '${OWNER}','${DIV}','${DEPT}','${STYLE}');
EOC
if [ $? -eq 1 ]; then
echo "Error in the stored procedure CNVT_TP_SUMMARY";exit 1
fi
exit 0

the parameters are db information related so I omitted before posting

U run_convert_pdm.ksh abc desf dev sdv XYZ "Mens Knit" 44 7542
1 Like

You should quote the variables in question.

#!/usr/bin/ksh
# run_convert_pdm.ksh
#
# Using SQL*Plus anaymous block to call a stored procedure
#
#
# This script is called with 8 params: userid, password, database, pdm db link, owner, div, dept
# access to TSS target - (user passwd sid) must be provided.
USER="$1"; export USER
PASSWD="$2"; export PASSWD
SID="$3"; export SID
PDM_DB="$4"; export PDM_DB
OWNER="$5"; export OWNER
DIV="$6"; export DIV
DEPT="$7"; export DEPT
STYLE="$8"; export STYLE
if [ -z "$8" ]; then
echo " **ERROR** $0 - 8 arguments not provided!"
echo " Usage: $0 userid, password, database, pdm db link, owner, div, dept, style"
exit 1 # failure
fi
rm ./run_convert_pdm_"${DEPT}".log
echo "**************** $(date +%c) Summary ${DEPT} ****************" >> ./run_convert_pdm_"${DEPT}".log
$ORACLE_HOME/bin/sqlplus ${USER}/${PASSWD}@${SID} >>./run_convert_pdm_"${DEPT}".log <<EOC
whenever sqlerror exit 1
execute CNVT_TP_SUMMARY('${PDM_DB}', '${OWNER}','${DIV}','${DEPT}','${STYLE}');
EOC
if [ $? -eq 1 ]; then
echo "Error in the stored procedure CNVT_TP_SUMMARY";exit 1
fi
exit 0

sorry I have double quoted variables but it did not work, I still got the same error message.

USER="$1";       export USER
PASSWD="$2";     export PASSWD
SID="$3";        export SID
PDM_DB="$4";     export PDM_DB
OWNER="$5";      export OWNER
DIV="$6";        export DIV
DEPT="$7";       export DEPT
STYLE="$8";      export STYLE

The error may be happening in the database itself, then. What is that procedure which is being called?

Another thing occurs to me -- is that "mens knit" or "men's knit"? An apostrophe in the string would mess up the syntax.

It is "Mens Knit" and procedure runs fine when executed in the database.
I get this error when I try to execute procedure from Unix, as I have mentioned
it works fine for div "Mens" but not for "Mens Knit".
As you can see v_div and v_dept are passing wrong values in the procedure.

U run_convert_pdm.ksh abc desf dev sdv XYZ "Mens Knit" 44 7542
As of now wrong parameters are being passing to procedure causing error
v_owner :XYZ 
v_div: "Mens
v_dept: Knit" 
v_style_in: 44
Right parameters for procedure
v_owner :XYZ 
v_div: Mens Knit
v_dept: 44 
v_style_in: 7542

What exactly are you typing U run_convert_pdm.ksh "Mens Knit" 44 7541 into? If it's not a shell, double-quotes may not be the thing you need to quote a string. It appears to be considering everything literally, even the quotes!

please find the steps.

  1. vi CONVERT_PDM_TEST
# --- BATCH 850 --------------------03/22/2012-----------
#parameters are userid, password, database, pdm db link, owner, div, dept, style
U run_convert_pdm.ksh abc desf dev sdv XYZ "Mens Knit" 44 7542
  1. run_pmcmd.ksh CONVERT_PDM_TEST

One point: This is partly a sqlplus problem. sqlplus requires single tics around quoted strings. The single tics or quotes on positional variables with spaces are lost once the variables are used inside the script.

usage: myscript.sh 'mens wear' 7155 'stuff'

# embed single quotes into a variable so sqlplus will like it
var1=$(printf "'%s'" "$1")
var3=$(printf "'%s'" "$3")

sqlplus me/mypasswd@somedb <<EOF
    select * from mytable
    where fld1 = $var1 
      and fld2 = $var2
      and fld3 = $var3;
EOF

I have tried following chnages but it did not work.
changes I have made are -

a. DIV="$6"
b. "'${DIV}'"
c. 'Mens Knit'

Step 1.run_pmcmd.ksh CONVERT_PDM_TEST

USER=$1;       export USER
PASSWD=$2;     export PASSWD
SID=$3;        export SID
PDM_DB=$4;     export PDM_DB
OWNER=$5;      export OWNER
DIV="$6";        export DIV
DEPT=$7;       export DEPT
STYLE=$8;      export STYLE
 
$ORACLE_HOME/bin/sqlplus ${USER}/${PASSWD}@${SID} >>./CONVERT_PDM_TEST${DEPT}.log <<EOC
whenever sqlerror exit 1
execute CNVT_TP_SUMMARY('${PDM_DB}', '${OWNER}',"'${DIV}'",'${DEPT}','${STYLE}');
EOC

Step 2. CONVERT_PDM_TEST

U run_convert_pdm.ksh abc pwd dev datadb XYZ 'Mens Knit' 44 7542

Thanks
Sandy

In what way does it not work? Is it any different from the way it did not work before?

It is still same error because parametes are not getting passed to stored procedure as expected.