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
How to call C functions in shell scripts? agarwal Shell Programming and Scripting 5 04-08-2008 09:03 PM
Issue calling scripts through CRON. vskr72 Shell Programming and Scripting 5 01-07-2008 04:12 PM
any possible solution on sql calling scripts manas_ranjan Shell Programming and Scripting 4 11-22-2007 02:02 AM
script calling other scripts hangs rein Shell Programming and Scripting 1 09-07-2007 02:26 AM
Calling SQL scripts through Shell Script madhunk Shell Programming and Scripting 18 06-14-2006 09:35 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-23-2007
Registered User
 

Join Date: Jul 2005
Location: Belfast
Posts: 49
Stumble this Post!
Calling functions in scripts directly

Hi,

I have a menu driven script that does various tasks, I want to be able to call functions directly from within other unix scripts from my menu script. Is this possible?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-23-2007
Playing with Ubuntu Now!
 

Join Date: Oct 2005
Location: Chennai
Posts: 364
Stumble this Post!
yes..Its possible

Its possible. Just make sure that the function is defined before its called.

Last edited by ranj@chn; 04-23-2007 at 04:18 AM. Reason: error in understanding
Reply With Quote
  #3 (permalink)  
Old 04-23-2007
Registered User
 

Join Date: Jul 2005
Location: Belfast
Posts: 49
Stumble this Post!
How do you do it ranj? What do you mean about path names? Could you give me an example?

Thanks
Reply With Quote
  #4 (permalink)  
Old 04-23-2007
Playing with Ubuntu Now!
 

Join Date: Oct 2005
Location: Chennai
Posts: 364
Stumble this Post!
A little explanation

Can you tell exactly what you are trying to achieve?
Reply With Quote
  #5 (permalink)  
Old 04-23-2007
Registered User
 

Join Date: Jul 2005
Location: Belfast
Posts: 49
Stumble this Post!
Bascially i have a menu:

doSQLSubMenu()
{
while true
do
showSQLSubMenu

read answer

MSG=

case $answer in
1) ;;
2) ;;
3) ;;

r|R) break;;

*) badChoice;;
esac
done
}

I want to make calls functions within different .sh scripts for option 1,2 and 3.

So say i had a function view() in a.sh

I would ideally want if you pressed 1 to call a.view()

Then another script perhaps b.sh

So if you pressed 2 it would call b.<function_name>

S.
Reply With Quote
  #6 (permalink)  
Old 04-23-2007
Playing with Ubuntu Now!
 

Join Date: Oct 2005
Location: Chennai
Posts: 364
Stumble this Post!
Fpath

There is a FPATH variable that should be set to point to the directory where the functions are defined. Check this link out - fpath
Reply With Quote
  #7 (permalink)  
Old 04-23-2007
Registered User
 

Join Date: Jul 2005
Location: Belfast
Posts: 49
Stumble this Post!
I'm not 100% sure i get this, is this saying create a libary of functions in another directory then ref this directory using the FPATH and just make calls to the required functions?

So if i have a file functions.sh that contains:

editSQLReleaseFile()
{
clear
echo "Editing..."
sleep 112
}

Then another file (say test.sh) with FPATH set to the location of the functions.sh file i can then make a call to editSQLReleaseFile from within test.sh?

i.e. in test.sh

echo "calling editSQLReleaseFile"
editSQLReleaseFile

?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:59 AM.


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

Content Relevant URLs by vBSEO 3.2.0