The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Passing Parameter in SED command dsrookie UNIX for Dummies Questions & Answers 2 06-09-2008 02:25 AM
wrong parameter passing! malle Shell Programming and Scripting 2 02-03-2007 07:21 AM
Passing parameter to makefile? manju_p High Level Programming 3 11-07-2006 04:39 AM
Parameter passing in a function fastgoon UNIX for Advanced & Expert Users 2 07-26-2006 06:10 AM
parameter passing kekanap Shell Programming and Scripting 8 07-20-2006 10:58 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-01-2007
rockysfr rockysfr is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 24
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 (permalink)  
Old 07-02-2007
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,411
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 (permalink)  
Old 07-02-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131

Code:
rdir = /products

You can't do that. Get rid of the spaces surrounding the equals sign.
  #4 (permalink)  
Old 07-02-2007
rockysfr rockysfr is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 24
Hey, thanks a bunch guys! Wouldn't have foreseen this since I'm more of a Java and C programmer than a shell scripter
  #5 (permalink)  
Old 07-02-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,433
There is an error in your while test :

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

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:13 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0