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.