The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Passing more than one argument in a function jisha Shell Programming and Scripting 1 04-23-2008 03:05 AM
How to pass variables to FUNCTION ? bh_hensem Shell Programming and Scripting 5 05-30-2007 11:54 PM
How do I pass a wild card as an argument eja UNIX for Dummies Questions & Answers 2 03-28-2007 11:03 AM
Passing Argument to Function AkumaTay UNIX for Dummies Questions & Answers 2 10-18-2001 03:24 PM
pass argument to a filename jpprial UNIX for Dummies Questions & Answers 1 09-03-2001 12:12 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 04-08-2007
Registered User
 

Join Date: Mar 2007
Posts: 11
Pass argument to function

Hi,
Can someone please explain to me how I can get a function to recognize a file given as an argument to a script.

Suppose the script has the argument as follows:

sh script file

and the function is as follows:
function display_file () {
cat $1
}

and it s then called
#main program
display_file

I find that the only way that I can get the file into the function is to make a copy in the main program like so:
cp $1 temp

I have read some lit on functions but haven't come accross this type of problem as far.

Thanks in advance,
Knotty.
Reply With Quote
Forum Sponsor
  #2  
Old 04-08-2007
Registered User
 

Join Date: Mar 2007
Posts: 11
Cool

It's alright folks,

after messing about with the script a bit I figured it out.

Just use the positional parameter as an argument to the function as so:

display_file $1
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:08 PM.


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