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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Can we pass array with call by value in function ranjithpr Shell Programming and Scripting 1 12-26-2007 09:22 AM
Pass argument to function Knotty UNIX for Dummies Questions & Answers 1 04-08-2007 05:26 AM
How to pass CSH variables up to the parent? ElCaito Shell Programming and Scripting 0 11-29-2006 11:30 PM
how to pass variables surrounded in double quotes to awk? cruiser AIX 4 03-24-2006 02:12 PM
Pass multiple variables to SQL script jagannatha Shell Programming and Scripting 1 10-25-2002 06:45 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 05-30-2007
Registered User
 

Join Date: May 2007
Posts: 6
How to pass variables to FUNCTION ?

Hi...

Actually, I want to pass a few variables to the function and print it. But, its looks like not working. Could some body help me how could i do that ?... below is my program...


PHP Code:
#!/usr/bin/ksh

usage()
{
    echo 
"Usage: $0 -n -a -s -w -d"
    
exit
}

rename()
{
    echo 
"rename $1 $2" 
}

if [ $
# -lt 1 ]; then
    
usage
fi

while getopts r:i:o opt
do
    case 
"$opt" in
        r
rename=1;;
        
iinput="$OPTARG";;
        
ooutput="$OPTARG";;
        ?) 
usage;;
    
esac
done

if [ $rename ]; then
    rename $input $output
fi 
Reply With Quote
Forum Sponsor
  #2  
Old 05-30-2007
Registered User
 

Join Date: May 2007
Posts: 13
Try this...

This is what you want

myfunc()
{
echo "read var1 "$1
echo "read var1 "$2
}

myfunc 1 2
Reply With Quote
  #3  
Old 05-30-2007
Registered User
 

Join Date: May 2007
Posts: 6
As example:
lets say i run it as
#./script.sh -r -i input -o output

Then, the programm will passed "input" and "ouput" to rename function and print it as below:-
# rename input output

Now its blank and not print anything...

Anyway I have tried your solution but its same... and result has been print out..
Reply With Quote
  #4  
Old 05-30-2007
Registered User
 

Join Date: May 2007
Posts: 6
hmm... i have got it...

....Something wrong with the getopt declaration.....
Reply With Quote
  #5  
Old 05-30-2007
Registered User
 

Join Date: Jan 2005
Posts: 212
Your color coding is excellent.
Reply With Quote
  #6  
Old 05-30-2007
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,212
The colon must follows the option
Code:
while getopts ri:o: opt
Jean-Pierre.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:33 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0