Passing the parameters using a function


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing the parameters using a function
# 1  
Old 04-12-2011
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 trend id's in a trend_ids.txt file, this file will be stored in /root/edw/trend/srcfiles

}

second function

Load_trend_data () {


Here I am connecting to the teradata database and calling a teradata store procedure as below

EXEC SP_TREND_DATA_LOAD( trend_ids) }


Now the file which I have generated using the first function has to be used in the place of trend_ids which is highlighted with red color below.the procedure has to execute for all the values which are present in the trend_id.txt


EXEC SP_TREND_DATA_LOAD( trend_ids) }

I tried using while read loop here , but I don't don't know how to use that here.


Can anyone tell me the above part, how can I code in the shell script.


Trend_ids's will have the below values

1
2
3
44
66666
5555


Thx,
Shruthi
# 2  
Old 04-12-2011
Think of it more as a script generating, text processing task.
Code:
while read tid
do
 echo "EXEC SP_TREND_DATA_LOAD($tid)"
done </root/edw/trend/srcfiles | . . . .

# 3  
Old 04-12-2011
Thanks for the reply...

I tried the below while loop in my code.

Code:
while read get_trend_ids 
do  
    echo "EXEC SP_TREND_DATA_LOAD($tid)" 
done /root/edw/trend/srcfiles

My script is getting executed but it's not picking any values from the txt file.

can you please have a look and tell me where I am doing it wrong.


Thx,
Shruthi

Last edited by fpmurphy; 04-12-2011 at 10:57 PM.. Reason: code tags please
# 4  
Old 04-12-2011
Try changing
Code:
done /root/edw/trend/srcfiles

to
Code:
done < /root/edw/trend/srcfiles

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Passing 2+ parameters to one command

I have a script that uses more than one parameter. It looks like this: for i in `cat /tmp/listofpolicies`; do for x in $(cat /tmp/lst |sed 's/^/\/usr\/openv\/netbackup\/db\/class\//g'); do /usr/openv/netbackup/bin/admincmd/bpplinclude $i -delete -f $x;done;done The problem is that the... (3 Replies)
Discussion started by: newbie2010
3 Replies

3. Shell Programming and Scripting

passing parameters with spaces

we are using following script to execute stored procedue. The problem is run_pmcmd.ksh script is using $* parameter which is not taking in account 'Men Shirt' parameter which includes spaces. 1. Step 1 run_pmcmd.ksh CONVERT_TEST script for run_pmcmd.ksh /u01/$(whoami)/run_pmcmd.ksh... (11 Replies)
Discussion started by: sandy162
11 Replies

4. Shell Programming and Scripting

Why double quotation marks doesn't work in ksh function parameters passing?

I'm working on AIX 6, ksh shell. The parameters are some strings quotated by double quotation marks which from a file. They are quotated because there may be spaces in them. Example: "015607" "10" " " "A"I want to pass these parameters to a shell function by writing the following command: ... (4 Replies)
Discussion started by: Shimmey
4 Replies

5. 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

6. Shell Programming and Scripting

Passing parameters to bash script function (or subroutine)

I've found a few posts regarding passing parameters to a function or subroutine, but for some reason when I try to run a command based on part with these parameters it's not working. If I have the function echo the parameters they show correctly so I believe they are being passed right but the... (2 Replies)
Discussion started by: withanh
2 Replies

7. 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

8. Shell Programming and Scripting

Passing global variable to a function which is called by another function

Hi , I have three funcions f1, f2 and f3 . f1 calls f2 and f2 calls f3 . I have a global variable "period" which i want to pass to f3 . Can i pass the variable directly in the definition of f3 ? Pls help . sars (4 Replies)
Discussion started by: sars
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. UNIX for Dummies Questions & Answers

Passing parameters in script

I have 2 scripts: script1 and script2 Script1 passes 4 parameters to script2 as follows #script1 code ... ... script2 $var1 $var2 $var3 $var4 Script2 uses the export command to know to expect these values #script2 export $1 $2 $3 $4 code ... ... The problem that I am having is... (1 Reply)
Discussion started by: eliguy
1 Replies
Login or Register to Ask a Question