LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-28-2013, 05:09 PM   #1
maddyfreaks
Member
 
Registered: May 2011
Posts: 70

Rep: Reputation: 0
Print function name - KSH


Hi All,

I am writing s shell script and where i need to get the Function Name automatically as i have some 20 functions .. so as soon as I execute the function I need to get the name.

Ex.
#!/bin/ksh
TEST1 ()
{
echo "Function 1"
}


TEST2 ()
{
echo "Function 2"
}

So when I call the function's I am getting outputs from echo but am not getting the function name ..

can some one guide me in getting the functionname ... in KSH

_maddy
 
Old 04-28-2013, 08:15 PM   #2
linuxguru1
LQ Newbie
 
Registered: Apr 2013
Location: Maryland
Distribution: RHEL
Posts: 7

Rep: Reputation: Disabled
It's been a while since I programmed in ksh. if I recall correctly the command line parameter passed to a function can be accessed just like the command line parameters passed to a script ($0 = function name, $1 = 1st argument, $2 = second argument, etc). Try "echo $0" and see what happens.
 
Old 04-28-2013, 08:36 PM   #3
gdejonge
Member
 
Registered: Aug 2010
Location: Netherlands
Distribution: Kubuntu, Debian, Suse, Slackware
Posts: 317

Rep: Reputation: 73
As addition to linuxguru

Use ksh function definition

Code:
function test1
{
  echo $0
}

test1
Will give you test1 as result.

if you use the bash type function definition
Code:
test1()
{
  echo $0
}

test1
you will get the name of the script file.

Note: I tested this with pdksh.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
write a programme to print function name bhupendra1984 Linux - Newbie 2 09-10-2009 11:37 PM
how to print function names & parmaters each time control enters the function? tanniru Linux - Networking 1 09-11-2008 01:21 AM
print job spools out but does not initiate print function john test Linux - Newbie 7 07-23-2008 05:13 PM
how to use sed's print function after a /d new_2_unix Linux - Newbie 7 10-12-2007 04:13 PM
Print function has gone Poof jhimes Linux - General 4 09-03-2005 05:07 PM


All times are GMT -5. The time now is 12:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration