Paramerter pass for function(sub routine) need help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Paramerter pass for function(sub routine) need help
# 1  
Old 05-27-2013
HP Paramerter pass for function(sub routine) need help

Hi,
Please help me here while passing the paramert to fuction i am facing problem.
i tryied passing 7 PARAMeter in side single quote,double quate even tried tild sign not working.

how can assign it properly .

usage ()
{
typeset -i NumPARAMs=$1
typeset -i PARAM1=$2
typeset PARAM2=$3
typeset -i PARAM3=$4
typeset -i PARAM4=$5
typeset PARAM5=$6
typeset PARAM6=$7
typeset PARAM7=$8
}

main ()
{
typeset -i NumPARAMs=$#
typeset PARAMeters=$*
usage $NumPARAMs $PARAMeters; [ $? -ne $SUCCESS ] && exit $FAILURE
}

debug log..

+ usage 7 15 5 2013 041190320 ALL "1/03, 1/41, 1/63" 1044
+ typeset -i NumPARAMs=7
+ typeset -i PARAM1=15
+ typeset PARAM2=5
+ typeset -i PARAM3=2013
+ typeset -i PARAM4=041190320
+ typeset PARAM5=ALL
+ typeset PARAM6="1/03,
+ typeset PARAM7=1/41,


output should be
+ check_usage 7 15 5 2013 041190320 ALL "1/03, 1/41, 1/63" 1044
+ typeset -i NumPARAMs=7
+ typeset -i PARAM1=15
+ typeset PARAM2=5
+ typeset -i PARAM3=2013
+ typeset -i PARAM4=041190320
+ typeset PARAM5=ALL
+ typeset PARAM6="1/03, 1/41, 1/63"
+ typeset PARAM7=1044


Thanks In Advance
Nitin
# 2  
Old 05-27-2013
what you get when you specify the 1/03, 1/41, 1/63 passed as

Code:
usage 7 15 5 2013 041190320 ALL 1/03 1/41 1/61 1044

?

once they are passed separately, you could have them re-assembled later and as per your requirement
# 3  
Old 05-27-2013
Hi,
this is raw input data at user side and i am separating that parameter later in shell. so user will provide in that way only.

but the use is going to provide input as "1/03 1/41 1/61".

usage 7 15 5 2013 041190320 ALL "1/03 1/41 1/61" 1044

and param 7 is just example and it may vary each time like anther example "1/04, 1/05, 1/40, 1/95, 1/99, 2/05, 2/06, 2/08, 2/64, 2/95, 2/99, 3/05, 3/06, 3/10, 3/95 3/99"
# 4  
Old 05-27-2013
Ah, you're expecting the shell to evaluate any quotes the user types in. Strings do not work that way. Once you get a quote inside a string, it's a literal character, not shell syntax.

If you want to parse quotes manually, one option is xargs.

Code:
$ xargs -n 1 <<EOF
usage 7 15 5 2013 041190320 ALL "1/03 1/41 1/61" 1044
EOF

usage
7
15
5
2013
041190320
ALL
1/03 1/41 1/61
1044

$

You could do something like

Code:
OLDIFS="$IFS"
IFS="
"
set -- `echo "$USERSTR" | xargs -n 1`
IFS="$OLDIFS"

...to have that string split into $1, $2, ... appropriately.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass variable from one function to another function?

updateEnvironmentField() { linewithoutquotes=`echo $LINE | tr -d '"'` b() } I want to pass variable named $linewithoutquotes to another method called b(), which is called from updateEnvironmentField() method. How to do the above requirement with shell script (1 Reply)
Discussion started by: pottic
1 Replies

2. Shell Programming and Scripting

How to pass function parameter to do loop?

Hi All, I have created one function for KSH and was running well with one parameter input since I just had to use $1 to get the parameter. Now I want to do loop for each parameter(actually filenames) . I have try to use do loop, but $i does not resolve to parameter instead it resolves to 1,... (5 Replies)
Discussion started by: mysocks
5 Replies

3. Shell Programming and Scripting

Pass command as a function parameter

Hi guys, can someome help with this question, I have defined a function that takes a command as a parameter, but when the command is executed from the function it will throw errors because what I believe is a special character escaping issue. I tried using the backslash to escape the pipe | and >... (2 Replies)
Discussion started by: marouanix
2 Replies

4. Shell Programming and Scripting

pass function as argument to a function

I have the following code : function1 () { print "January" } function2() { case $1 in January) print "Dzisiaj mamy styczen" ;; *) ;; } main() { (1 Reply)
Discussion started by: presul
1 Replies

5. Shell Programming and Scripting

Pass parameters to function

Hi, for example I have this function: function get_param () { test=echo "some string" test2=echo "someother string" } I want to call this function and get test or test2 result, how do I do that ? Thank you (2 Replies)
Discussion started by: ktm
2 Replies

6. Shell Programming and Scripting

How to pass an array from SHELL to C function

Hi, I have an output generated from a shell script like; 0x41,0xF2,0x59,0xDD,0x86,0xD3,0xEF,0x61,0xF2 How can I pass this value to the C function, as below; int main(int argc, char *argv) { unsigned char hellopdu={above value}; } Regards Elthox (1 Reply)
Discussion started by: elthox
1 Replies

7. Shell Programming and Scripting

pass parameter to function

HI all I have a code like ############################################## minyear() { curryear=$1 echo $curryear } ##Main Program ## minyear exit ####### when i execute "sh scriptname 2005" output should be like 2005 but the output is blank. I guess i need to pass parameter to... (3 Replies)
Discussion started by: vasuarjula
3 Replies

8. Shell Programming and Scripting

Can we pass array with call by value in function

I want to pass an array in my function, And my function will be changing the elements of the array in the fuction, but it should not affect the values in my array variable of main function (1 Reply)
Discussion started by: ranjithpr
1 Replies

9. Shell Programming and Scripting

How to pass variables to FUNCTION ?

Hi... Actually, I want to pass a few variables to the function and print it. But, its looks like not working. Could some body help me how could i do that ?... below is my program... #!/usr/bin/ksh usage() { echo "Usage: $0 -n -a -s -w -d" exit } rename() { echo "rename $1 $2"... (5 Replies)
Discussion started by: bh_hensem
5 Replies

10. UNIX for Dummies Questions & Answers

Pass argument to function

Hi, Can someone please explain to me how I can get a function to recognize a file given as an argument to a script. Suppose the script has the argument as follows: sh script file and the function is as follows: function display_file () { cat $1 } and it s then called #main program... (1 Reply)
Discussion started by: Knotty
1 Replies
Login or Register to Ask a Question