Strange parameter passing problems (KSH)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Strange parameter passing problems (KSH)
# 1  
Old 07-01-2007
Strange parameter passing problems (KSH)

Hi all,

I'm having a rather peculiar problem involving parameter passing with declared functions in my shell script. Hope to get some advice here.

A brief description of my code is as follows:

Quote:

# assign target directory to variable rdir
rdir = /products

# method showmenu finds all subdirectories from a given directory, places their names in an array and then outputs them in the form of a menu

showmenu() {

set -A items $(find $1/* -type d -prune)

i=0
while ((i<${#items[i]}))
do
echo "$i. ${items[$i]}"
((i+=1))
done

}

# in the next part of program, call showmenu and pass variable rdir as the parameter

showmenu $rdir
However, I'm not getting the results I wanted. If I pass in $rdir, I'm going to end up referencing from the root (ie. / ) and printing out the root directory names (ie. bin, boot, dev, etc, home). However, if I hard code the directory location in place of $1 in showmenu(), I'll see the correct directory names.

Any ideas as to why the directory names are not showing?

Thanks in advance.
# 2  
Old 07-02-2007
You have spaces at either side of the equals sign here...
Code:
rdir = /products

This is the wrong syntax for declaring a variable. Instead, the shell would try to run an executable called "rdir" with two arguments "=" and "/products".
# 3  
Old 07-02-2007
Code:
rdir = /products

You can't do that. Get rid of the spaces surrounding the equals sign.
# 4  
Old 07-02-2007
Hey, thanks a bunch guys! Wouldn't have foreseen this since I'm more of a Java and C programmer than a shell scripter Smilie
# 5  
Old 07-02-2007
There is an error in your while test :
Code:
i=0
while ((i<${#items[*]}))
do
   echo "$i. ${items[$i]}"
   ((i+=1))
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Passing output parameter(Oracle) to variable in ksh Script

Hello, I have researched and tried many way to pass OUT parameter to be stored in variable in KSH Script.Still not success, please help. Here is my Store Procedure. create procedure testout3(v_in varchar2,v_out OUT integer) as begin v_out := 1; end; Here is my testvout.ksh #!/bin/ksh... (1 Reply)
Discussion started by: palita2601
1 Replies

2. Shell Programming and Scripting

Passing parameter through file

Hi , I am passing date parameter through file my shell script testing.sh is #set -x #set -v asd=$1 asd1=$2 echo $asd echo $asd1 Passing parameter as below sh testing.sh `cat file1.txt` Output (2 Replies)
Discussion started by: kaushik02018
2 Replies

3. Shell Programming and Scripting

Passing parameter more than 9

Hi, I've written a script where eleven parameter to be passed from command line which is inserting into an oracle table, it is working but the tenth and 11th parameter are not accepting as given it is referring to 1st parameter. HERE IS THE SCRIPT #!/bin/ksh #set -o echo $*... (4 Replies)
Discussion started by: sankar
4 Replies

4. Shell Programming and Scripting

Passing parameter to script, and split the parameter

i am passing input parameter 'one_two' to the script , the script output should display the result as below one_1two one_2two one_3two if then echo " Usage : <$0> <DATABASE> " exit 0 else for DB in 1 2 3 do DBname=`$DATABASE | awk -F "_" '{print $1_${DB}_$2}` done fi (5 Replies)
Discussion started by: only4satish
5 Replies

5. Programming

passing float parameter

I am surprised by GCC (this is ver. 4.2.4, Ubuntu 32 bit Intel) when a function declares a float parameter and it's prototype is missing, the parameters are messed up. Please see my code below: ~/test$ cat x1.c #include <stdio.h> #include <stdlib.h> set_p(int p1, float p2, int p3, int p4)... (7 Replies)
Discussion started by: migurus
7 Replies

6. Shell Programming and Scripting

Passing parameter in quotes

Hi, PW='/as sysdba'; export PW in other module I call sqlplus ${PW} (this line I unable to change!) How I can define PW so that sqlplus calls PW in quotes i.e sqlplus '/as sysdba' I tried like this PW="'/as sysdba'"; export PW - no luck Thanks in advance (2 Replies)
Discussion started by: zam
2 Replies

7. Shell Programming and Scripting

Parameter Passing problem

Hi All, I developed a KSH script which will accept two parameters as input. These two parameters are some directories paths. In the script i am validating the number of paramaters it received as below #-------------------------------------- # Check Command line arguments... (8 Replies)
Discussion started by: Raamc
8 Replies

8. Shell Programming and Scripting

wrong parameter passing!

Hi all I have a script which will take input as filename and passes it to a java program. It is as follows -------------------------------- FILENAME=$1 echo $FILENAME ${JAVA_HOME}/bin/java -cp DateProvider $FILENAME ------------------------------------------------- when I execute the same... (2 Replies)
Discussion started by: malle
2 Replies

9. UNIX for Advanced & Expert Users

Parameter passing in a function

I need to pass a parameter to a function in a script. My parameter is a string. When I display the parameter within my function, I only get the first word from string I pass in. How can I make the function receive the whole string (and not terminate at the first space it encounters)?. part of... (2 Replies)
Discussion started by: fastgoon
2 Replies

10. Shell Programming and Scripting

parameter passing

Hallo everyone, This is my problem below: /home/cerebrus/pax=>vat class2.sh ksh: vat: not found /home/cerebrus/pax=>cat class2.sh #!/bin/ksh set -x bdf|grep appsdev|awk '{ print $5 }'> class3 dd={cat class3} echo $dd /home/cerebrus/pax=> /home/cerebrus/pax=>./class2.sh + bdf +... (8 Replies)
Discussion started by: kekanap
8 Replies
Login or Register to Ask a Question