- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Creating Functions
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
Discussions
Discussions
Forums
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
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
тАО05-06-2005 01:06 AM
тАО05-06-2005 01:06 AM
When I create a function by pasting the code to create the function into a script and run the script, the script runs but when I try to execute the function, I get the message
ksh: get_time2: not found
However, if I just paste the code to the command line, it works.
For example:
oracle [/m02/oracle/scripts]
#get_time.ksh
oracle [/m02/oracle/scripts]
#get_time2
ksh: get_time2: not found.
oracle [/m02/oracle/scripts]
#more get_time.ksh
function get_time2 {
TIME=$(date '+%m/%d/%y-%H:%M:%S')
printf "$TIME\n"
}
oracle [/m02/oracle/scripts]
#function get_time2 {
> TIME=$(date '+%m/%d/%y-%H:%M:%S')
> printf "$TIME\n"
> }
oracle [/m02/oracle/scripts]
#get_time2
05/05/05-18:20:10
Question: how can I create the functions using code that executes within a shell script?
Solved! Go to Solution.
- Tags:
- function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-06-2005 01:31 AM
- Tags:
- source
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-06-2005 01:48 AM
тАО05-06-2005 01:48 AM
Re: Creating Functions
Gilbert,
you may get more help in the HPUX scripting forum
http://forums1.itrc.hp.com/service/forums/categoryhome.do?categoryId=150
Purely Personal Opinion
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-06-2005 02:33 AM
тАО05-06-2005 02:33 AM
Re: Creating Functions
will move it to the scripting forum !
Gil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-06-2005 08:53 PM
тАО05-06-2005 08:53 PM
Re: Creating Functions
You cannot call a function from the prompt, only a existing script.
Try the following:
Content get_time.ksh
#####
function get_time2 {
TIME=$(date '+%m/%d/%y-%H:%M:%S')
printf "$TIME\n"
}
get_time2
#####
Darrel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-07-2005 12:49 PM
тАО05-07-2005 12:49 PM
Re: Creating Functions
for a simple example:
in get_time.ksh
FPATH=/m02/oracle/functions
get_time2
create a file named get_time2 in the /m02/oracle/functions directory with your funtion definition within
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-08-2005 05:23 AM
тАО05-08-2005 05:23 AM
Re: Creating Functions
check_network() {
$SCMD network status > /dev/null
rcode=$?
# echo "Network status return code: ${rcode}"
return $rcode
} # End check_network()
It is sourced into another script that with code like this:
. /usr/contrib/bin/functions
Any scrip; with this line can now call the function check_network()
Thats from a bash script but I think it should work with the korn shell.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-08-2005 11:02 PM
тАО05-08-2005 11:02 PM
Re: Creating Functions
In general, if you create a function in one shell, only that shell recognises the function.
When executing a script using ./script.sh a new shell is opened, script is executed, feedback is given and shell gets closed.
That's why you can't create a script with a function and after running the script, trying to execute the function.
If you run the script by . script.sh, the script is executed in the current shell, but that's not recommended. The FPATH variable is preferred.
Cheerio,
Renarios