|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
need KSH help! passing variables to functions
okay, I have the following code. (korn shell script in unix).
function abc { print $1 } #main starts here for((i=1; i<$#; i++)) do abc $i done #end of program #the $# variable is a count of the number of vars #passed to main from the command line. #here, $i is the first command line variable. I want to #pass that variable to function abc. then i want the #value of $2, then value of $3, etc. when i do this, it actually passes $i rather than the value of $i. i have tried every type of syntax modification to the function call, but can't seem to make this work. any help would be GREATLY appreciated. thank you! |
|
#2
|
|||
|
|||
|
I don't think you understand how variables work. If you do:
i="hello" echo $i The echo statement is print "hello". If you put a statement like hello="good-bye" in front of it, that won't change anything |
|
#3
|
|||
|
|||
|
I understand that. im just not sure how i would pass the value of $1 for example (first iteration of loop), to function abc.... i realize that abc $i will not work, and i understand why, but i don't know what to use in its place.
|
|
#4
|
|||
|
|||
|
I would do something like this:
function abc { print $1 } #main starts here while(($#)) do abc $1 shift done |
|
#5
|
|||
|
|||
|
Quote:
You have instructed the system to display numbers 1, 2, 3, etc and it has done so. Write eval abc \$$i instead of abc $i Regards zlutovsky |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > KSH help! passing variables to functions |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|