count no of arguments passed to a function


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting count no of arguments passed to a function
# 1  
Old 05-20-2008
Java count no of arguments passed to a function

hi
i have a function
abc
{

//from this function i am passing args to antoher function like

def a b c j k l
}
now i want to count the no of args coming to def() function and iterate over those values

is there any way to do this one

please help
# 2  
Old 05-20-2008
Code:
$ cat test.sh                                                                                                                                                           
echo 'num of args: '$#
for arg in "$@"; do echo 'arg: '$arg; done
$ sh test.sh a 2 c 4 
num of args: 4
arg: a
arg: 2
arg: c
arg: 4

# 3  
Old 05-21-2008
duplicate thread, proceed here
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calling function, based on agrument passed.

Dears, #!/bin/bash func1() { echo "func1" } func2() { echo "func2" } func3() { echo "func3" } (5 Replies)
Discussion started by: sadique.manzar
5 Replies

2. Shell Programming and Scripting

How can multiple arguments be passed to shell script?

My requirement is that I want to pass similar argument to a shell script and process it in the script. Something like below: myScript.sh -c COMPONENT1 -c COMPONENT2 -a APPNote: -c option can be specified multiple times and -a is optional parameter I know this can be achieved using... (2 Replies)
Discussion started by: rajdeep_paul
2 Replies

3. Shell Programming and Scripting

Deleting columns passed as arguments to the script

Hi all, I am trying to delete columns in a file using a script. The columns that need to be deleted are passed as arguments to the script. The script should look like this > delete_columns.sh <file_name.txt> <column_numbers_to_be_deleted> The contents of the file_name.txt will be like ... (5 Replies)
Discussion started by: VNR
5 Replies

4. Shell Programming and Scripting

Store all the passed arguments in an array and display the array

Hi I want to write a script which store all the parameters passed to the script into an array. Once it is stored I want scan through the array and and delete those files for last month present inside the directory. The files in directory is appneded with YYYY_MM_DD. I want to know how can I... (3 Replies)
Discussion started by: dgmm
3 Replies

5. UNIX for Advanced & Expert Users

Function not called when no arguments is passed

Hi Guys, I am trying to pass arguments to the script i am wrinting. When no argument is passed or wrong argument is passed, the script needs to output the way it needs to be called and exit. Currently, when no arguments is passed, it is not getting exited but goes on assuming those... (3 Replies)
Discussion started by: mac4rfree
3 Replies

6. Red Hat

how can i know what arguments are passed to a pre install rpm script?

hi, i have an rpm, and i am looking at the presinstall script. i can see it takes in an argument, but what i do not know is how this argument is passed to the script? is there something that calls the preinstall script? i thought the preinstall script was the first thing executed. thanks (2 Replies)
Discussion started by: JamesByars
2 Replies

7. Shell Programming and Scripting

Check if passed arguments is users

i want to check passed arguments one by one and if it is user print home director of that user (3 Replies)
Discussion started by: testman84
3 Replies

8. Shell Programming and Scripting

How to pass arguments to SQL file passed in shell script?

Hi, I am using SYBASE database. in my script i am connecting to DB via using isql. isql -U${S_USER} -S${S_SERV} -D${S_DB} -P${S_PWD} -b0 -w3000 -h0 -s"|" -i${MYDIR}/ABC.sql -oXYZ.txt << FINSQL i am taking a ABC.sql file to use the queries written in it and storing the output in... (3 Replies)
Discussion started by: dazdseg
3 Replies

9. Shell Programming and Scripting

counting no of argumnts passed to a function

hi i have a function abc() { //from this function i am passing some args to another function def() } def() { //Now i need to calculate the no of input args and iterate through them } please help (4 Replies)
Discussion started by: satish@123
4 Replies

10. Shell Programming and Scripting

How to read values that are passed to the shell function in ksh.

In ksh shell, There is a function f1. function f1 { How to read here?? .... .... } I am passing values to fuunction f1 as f1 "A" "B" Please tell me how to read the passed values in function f1. Advance Thanks & Regards Prashant (2 Replies)
Discussion started by: prashant43
2 Replies
Login or Register to Ask a Question