Operating System - Linux
1826212 Members
2481 Online
109691 Solutions
New Discussion

How to show function body in a script

 
Edgar Matzinger
Advisor

How to show function body in a script

ls,

I have a question: Why does ksh (and sh-posix BTW) behave differently in a terminal or a script?

Take the script below (in /tmp/tst):

---------8<---------------------8<------------
#! /usr/bin/ksh -p

function t
{
echo "This is function t"
}

function u
{
echo "This is function u"
}

echo "List all functions\ntypeset -f"
typeset -f
echo "List only function t\ntypeset -f t"
typeset -f t
---------8<---------------------8<------------
And execute them. The output of /tmp/tst:

List all functions
typeset -f
function t
function u
List only function t
typeset -f t
function t

And the output of ". /tmp/tst":

List all functions
typeset -f
function t
{
echo "This is function t"
}
function u
{
echo "This is function u"
}
List only function t
typeset -f t
function t
{
echo "This is function t"
}

How come? Thanks, Edgar.
1 REPLY 1
Edgar Matzinger
Advisor

Re: How to show function body in a script

ls,

I've forgotten to mention: HP-UX 11.00,
11.11 and 11.23

MTIA, cu l8r, Edgar.