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
calling function inside awk jisha Shell Programming and Scripting 2 04-14-2008 08:44 AM
Calling a function ashika UNIX for Dummies Questions & Answers 5 09-12-2006 08:58 PM
Calling other file function maldini Shell Programming and Scripting 3 08-19-2005 03:23 AM
calling c++ function from script Lebamb High Level Programming 3 06-24-2003 10:53 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 08-22-2008
douknownam douknownam is offline
Registered User
  
 

Join Date: May 2004
Posts: 35
Calling on function from file??

This may sounds dumb, but can I call on a function from a file? For example, I have a function file full of functions like below (no shell designation):


Code:
func { echo "blah blah blah 1" }

func2 { echo "blah blah blah 2" }

func3 { echo "blah blah blah 3" }

Am I able to call on any one of these specific functions from another script? If so, how? TIA
  #2 (permalink)  
Old 08-23-2008
redoubtable redoubtable is offline
Registered User
  
 

Join Date: Aug 2008
Location: Portugal
Posts: 242
(Talking about bash)

Yes, you can use those functions from another file if they have the correct syntax which is not the case.

For bash functions you could have a file say file_number_one.sh:

Code:
function func { echo "bla bla bla1"; }

and then from another script you could have:

Code:
. ./file_number_one.sh

func

  #3 (permalink)  
Old 08-24-2008
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,407
ya exactly..
for that you have to source your script as redoubtable suggested..
  #4 (permalink)  
Old 08-24-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
As an aside, function is a Bashism. The POSIX way to declare a function is


Code:
func () { body of function; }

I care because it bit me when I switched shells (or rather, Ubuntu switched shells on me).
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 02:04 PM.


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