- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to call a function (in a separate directory) f...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2003 10:30 AM
07-24-2003 10:30 AM
Ex:
#pwd
/home/sam
#cat call_fun.sh
=============
export PATH=$PATH:/home/functions
echo HELLO
test
test2
=================
But this script only echoes HELLO but does
call the command in the function. Want an output of commands in file test and test2
# pwd
/home/functions
================
#ls
test test2
# cat test
###File name: test
----------------
test()
{
pwd
whoami
}
--------------------
# cat test2
###File name: test2
----------------
test2()
{
whodu
ls >out
}
Thanks a bunch
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2003 10:33 AM
07-24-2003 10:33 AM
Re: How to call a function (in a separate directory) from script ?
For example,
. /fullpath/function1.sh
Hope this helps.
Hai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2003 10:48 AM
07-24-2003 10:48 AM
SolutionYou're on the right track. Set the environmental variable FPATH in your hosting shell. Here's an example:
/tmp/fct.sh
#!/usr/bin/sh
FPATH=/tmp/fcts
testme
exit 0
the 'testme' function looks like this:
#!/usr/bin/sh
function testme
{
date
}
...and is named '/tmp/fcts/testme' with execute permissions.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2003 11:12 AM
07-24-2003 11:12 AM
Re: How to call a function (in a separate directory) from script ?
Additionally, you can put function difinitions in your environment file (.kshrc, etc) if you want them to be defined whenever the shell is invoked interatively.
if you want to improve your shell's performance, put functions that you use infrequently in a directory named by FPATH, instead of putting the definitions in your environment file and use set -o nolog to keep function definitons from being stored in the history file.
a function that becomes defined the first time it is referenced is called an auto-loaded function. Its primary advantage is better performance, since the shell does not have to read the function definiton if you never referenced the function.
you can specifiy that a function auto-load with the "autoload" preset alias. when the shell first encounters an auto-loaded function, it uses the FPATH varialbe to search for a filename whose name matches that of the function. this file must contain the definition of this function.
you can load a library of related functions with the first reference to any of its members, by putting them all in one file. For each function defined, you can us "ln" to create a filename with the name of the function that refers to this file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2003 11:14 AM
07-24-2003 11:14 AM
Re: How to call a function (in a separate directory) from script ?
And you are on the right path to 10 pts !!!.
Out of curiosity, what does FPATH does. I was trying
PATH=$PATH:/tmp/functs in the script
But it would not work.
huge Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2003 11:18 AM
07-24-2003 11:18 AM
Re: How to call a function (in a separate directory) from script ?
Thanks for the explanation for a question that I asked JRF. FPATH was little confusing to me. Until you explained it. Much thanks to you.
Sam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2003 11:20 AM
07-24-2003 11:20 AM
Re: How to call a function (in a separate directory) from script ?
'FPATH' is the search path for function definitions (colon-delimited, as you would expect). Have a look at the 'sh-posix' man pages.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2003 11:34 AM
07-24-2003 11:34 AM
Re: How to call a function (in a separate directory) from script ?
tmp/fct.sh
#!/usr/bin/sh
FPATH=/tmp/fcts
testme
echo "NEXT FUNTION"
testme2
exit 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2003 11:42 AM
07-24-2003 11:42 AM
Re: How to call a function (in a separate directory) from script ?
Thanks all
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2003 11:43 AM
07-24-2003 11:43 AM