passing parameters with spaces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting passing parameters with spaces
# 8  
Old 08-27-2012
Quote:
Please let me know where and how to fix it.
Repair the calling program so that it provides the parameters correctly.
# 9  
Old 08-28-2012
Thanks I have added double quotes in parameters in Step 2 and step 3 but still the result is not as expected.
2. Step 2
script for CONVERT_TEST
Code:
#parameters are userid, password, database, db link, owner, div, dept, style
U run_convert.ksh "abc" "desf" "dev" "sdv" "XYZ" "Men Shirt" "44" "7542"

3. Step 3
script for run_convert.ksh
Code:
USER="$1";       export USER
PASSWD="$2";     export PASSWD
SID="$3";        export SID
DB="$4";         export 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_TEST${DEPT}.log <<EOC
whenever sqlerror exit 1
execute CNVT_SUMMARY('${DB}', '${OWNER}','${DIV}','${DEPT}','${STYLE}');
EOC

4. Wrong Result because "Men Shirt" is in two different lines
Code:
"abc"
"desf"
"dev"
"sdv"
"XYZ"
"Men
Shirt"
"44"
"7542"

# 10  
Old 08-28-2012
Quote:
Originally Posted by sandy162
Thanks I have added double quotes in parameters in Step 2 and step 3 but still the result is not as expected.
If your arguments can't be trusted, you'll have to reprocess them from scratch. Since they appear to contain quote characters, that's at least somewhat possible. xargs understands quotes, making it useful here.

It will also strip them out, allowing you to put them back only where you want them.

Code:
echo "Arguments before:"
printf "%s\n" "$@"

echo "$@" | tr '\n' ' ' | xargs -n 1 > /tmp/$$ # Print one argument per line into /tmp/$$
# Clear arguments
set --

# Read arguments back into $1 $2 ... in turn
while read LINE
do
        set -- "$@" "$LINE"
done < /tmp/$$
rm -f /tmp/$$

# See if they've been improved
echo "Arguments after:"
printf "%s\n" "$@"

It would be far better to fix the thing that's calling it, but I'm guessing your refusal to consider it means that's not an option.

Last edited by Corona688; 08-28-2012 at 05:15 PM..
# 11  
Old 08-28-2012
Thanks for reply. I am open for changing calling script but have no idea what to change and which script to change.
Parameters which are being passed dont have quotes around

Code:
U run_convert.ksh abc desf dev sdv XYZ Men Shirt 44 7542

this is how parameter should be passed to stored procedure from script.
Code:
$1 - abc
$2 - desf
$3 - dev
$4- sdev
$5 - XYZ
$6 - Men Shirt 
$7 - 44
$8 - 7542

# 12  
Old 08-29-2012
Quote:
Originally Posted by sandy162
Thanks for reply. I am open for changing calling script but have no idea what to change and which script to change.
Parameters which are being passed dont have quotes around
They obviously do, if my printf statement printed this:
Code:
"Men
Shirt"

My statement wouldn't have added those quotes, they must have been in the string.

So, try my code.
Quote:
this is how parameter should be passed to stored procedure from script.
If it doesn't have quotes, your script can't guess which arguments belong where. Maybe the extra strings belong with "Mens" -- but maybe they belong with "XYZ" instead! Only the thing which called your script would know.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing parameters with spaces between scripts

I have 2 scripts. test.sh, which calls submit2.sh. One of the parameters contains space and is quoted. ((((./submit2.sh Group_1_2_AMS_DAILY_CORE_GRP03 AMS AMS_D 'DAILY REPORT PROCEDURES'; echo $?>&3) | tee 1.log >&4)3>&1) | (read xs; exit $xs)) 4>&1 echo parm 1 = $1 echo parm 2 = $2... (1 Reply)
Discussion started by: andyclam
1 Replies

2. Shell Programming and Scripting

Help with passing parameters from a file

Hello Everyone, I have developed a shell script which takes schema id and password as parameter to login into database using sqlplus,runs a query and mails the result. My requirement is that, I dont want to pass userid and password as parameters.Instead,I want to pass say Environment... (4 Replies)
Discussion started by: karthik adiga
4 Replies

3. Shell Programming and Scripting

Passing Parameters to Crontab

Hello Experts, I have a requirement to pass some parameters to Linux cron tab. For ex: My default cron entry looks like this as below: ------------------------------- 55 10 * * --... (7 Replies)
Discussion started by: MaheshChaudhari
7 Replies

4. Shell Programming and Scripting

passing parameters to the script

how can i make a script to run only when parameters are given, if parameters are not given it should through an error , saying "please enter a parameter" for ex: i want a find command to run only when the parameters are given (4 Replies)
Discussion started by: knip
4 Replies

5. UNIX for Dummies Questions & Answers

Passing the parameters through a file

Hi All, I have written a shell script and the script is working fine, I am passing my MIT_ID(NUMBER VALUE) to the shell script from the command prompt and my script is executing as expected. Now I have to pass all the MIT_ID's from a .txt file to the shell script,as I am automating this I... (6 Replies)
Discussion started by: gaur.deepti
6 Replies

6. Shell Programming and Scripting

Passing the parameters using a function

Hi All, I am new to shell scripting required some help in passing the parameter value to the shell script. I am writing a shell script, in the script I have created two functions as below. first function get_trend_ids () { Here I am connecting to the database and getting all the... (3 Replies)
Discussion started by: shruthidwh
3 Replies

7. Shell Programming and Scripting

Automate the passing of parameters

I am writing a script that should read the csv file and pass the values in the file as parameters to the script. The csv file looks like this: TEST_1,20110221 TEST_2,20110220 TEST_3,20110218,20110219 Currently this is how i am running the script ./test.sh <param1> <date> Ex: ./test.sh... (6 Replies)
Discussion started by: stunnerz_84
6 Replies

8. Shell Programming and Scripting

passing parameters using awk

Hi, The below script is working fine awk1.sh ======= awk BEGIN { FS="|" } FNR==NR { f1=$2; next } $1 in f1 && $2 =="xx" && $1 == "DAILY_JOB" {print $3} awk -f awk1.sh a.txt b.txt--Its working fine . When passing parameters its not working .Any help it should be appereciated. ... (4 Replies)
Discussion started by: akil
4 Replies

9. Shell Programming and Scripting

passing more than 9 parameters

hi, i am passing around 14 parameters for a script a=$1 b=$2 c=$3 d=$4 e=$5 f=$6 g=$7 h=$8 i=\"${9}\" shift j=\"${1}\" still for j it is displaying the 1st parameter value..how to make it take the 10th parameter (2 Replies)
Discussion started by: dnat
2 Replies

10. Shell Programming and Scripting

problem in passing parameters with spaces

hi im passing 4 parameters to a file....like /userr/script/go.sql $1 $2 $3 $4 and i get them in the other script and make and insert into the tabke insert into xy values('&1','&2','&3','&4'); what is the problem is tht when any one paramter has a space in them like "airtel... (2 Replies)
Discussion started by: njraman
2 Replies
Login or Register to Ask a Question