Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 04-28-2013, 06:09 PM   #1
Registered: May 2011
Posts: 74

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.

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

Old 04-28-2013, 09:15 PM   #2
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, 09:36 PM   #3
Registered: Aug 2010
Location: Netherlands
Distribution: Kubuntu, Debian, Suse, Slackware
Posts: 317

Rep: Reputation: 73
As addition to linuxguru

Use ksh function definition

function test1
  echo $0

Will give you test1 as result.

if you use the bash type function definition
  echo $0

you will get the name of the script file.

Note: I tested this with pdksh.


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-11-2009 12:37 AM
how to print function names & parmaters each time control enters the function? tanniru Linux - Networking 1 09-11-2008 02:21 AM
print job spools out but does not initiate print function john test Linux - Newbie 7 07-23-2008 06:13 PM
how to use sed's print function after a /d new_2_unix Linux - Newbie 7 10-12-2007 05:13 PM
Print function has gone Poof jhimes Linux - General 4 09-03-2005 06:07 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:27 PM.

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