Extract full function definitions
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
Given:
$ cat test.ksh
doit()
doi1()
echo doi1 "$@"
doi2()
echo doi2 "$@"
doi1 a
doi2 b
doit
functions doit
typeset -f doit
Why do I get this output (doi2() and the last } are missing):
$ perl -e '$a=join("",<>);system("ksh","-c",$a)' test.ksh
doi1 a
doi2 b
doit() {
doi1()
echo doi1 "$@"
echo doi2 "$@"
doit()
doi1()
echo doi1 "$@"
echo doi2 "$@"
and not this:
doi1 a
doi2 b
doit()
doi1()
echo doi1 "$@"
doi2()
echo doi2 "$@"
doi1 a
doi2 b
doit()
doi1()
echo doi1 "$@"
doi2()
echo doi2 "$@"
doi1 a
doi2 b
Is there any way I can tell ksh to leave the function names untouched and thus give me the full function definition?
$ ksh --version
version sh (AT&T Research) 93u+ 2012-08-01
ksh
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Given:
$ cat test.ksh
doit()
doi1()
echo doi1 "$@"
doi2()
echo doi2 "$@"
doi1 a
doi2 b
doit
functions doit
typeset -f doit
Why do I get this output (doi2() and the last are missing):
$ perl -e '$a=join("",<>);system("ksh","-c",$a)' test.ksh
doi1 a
doi2 b
doit() {
doi1()
echo doi1 "$@"
echo doi2 "$@"
doit()
doi1()
echo doi1 "$@"
echo doi2 "$@"
and not this:
doi1 a
doi2 b
doit()
doi1()
echo doi1 "$@"
doi2()
echo doi2 "$@"
doi1 a
doi2 b
doit()
doi1()
echo doi1 "$@"
doi2()
echo doi2 "$@"
doi1 a
doi2 b
Is there any way I can tell ksh to leave the function names untouched and thus give me the full function definition?
$ ksh --version
version sh (AT&T Research) 93u+ 2012-08-01
ksh
ksh
asked Jul 18 at 15:16
Ole Tange
11.2k1342101
11.2k1342101
add a comment |Â
FWIW, you'll get the same behaviour withksh93 -c "$(cat test.ksh)"
.
â Kusalananda
Jul 18 at 15:37
@Kusalananda Yes. That is an even simpler example.
â Ole Tange
Jul 18 at 15:41
Strange bug. It seems to be triggered by ksh not having a script name:ksh <test.ksh
has the same effect. It's not due to having multiple function definitions: the display is cut off after the end of the definition ofdoi1
, except for any other nested function definition.
â Gilles
Jul 18 at 20:03
Can I set a (fake) script name? Somewhat similar to$0="myname"
in perl?
â Ole Tange
Jul 19 at 0:02
FWIW, you'll get the same behaviour with
ksh93 -c "$(cat test.ksh)"
.â Kusalananda
Jul 18 at 15:37
FWIW, you'll get the same behaviour with
ksh93 -c "$(cat test.ksh)"
.â Kusalananda
Jul 18 at 15:37
@Kusalananda Yes. That is an even simpler example.
â Ole Tange
Jul 18 at 15:41
@Kusalananda Yes. That is an even simpler example.
â Ole Tange
Jul 18 at 15:41
Strange bug. It seems to be triggered by ksh not having a script name:
ksh <test.ksh
has the same effect. It's not due to having multiple function definitions: the display is cut off after the end of the definition of doi1
, except for any other nested function definition.â Gilles
Jul 18 at 20:03
Strange bug. It seems to be triggered by ksh not having a script name:
ksh <test.ksh
has the same effect. It's not due to having multiple function definitions: the display is cut off after the end of the definition of doi1
, except for any other nested function definition.â Gilles
Jul 18 at 20:03
Can I set a (fake) script name? Somewhat similar to
$0="myname"
in perl?â Ole Tange
Jul 19 at 0:02
Can I set a (fake) script name? Somewhat similar to
$0="myname"
in perl?â Ole Tange
Jul 19 at 0:02
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Â
draft saved
draft discarded
Â
draft saved
draft discarded
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f457031%2fextract-full-function-definitions%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
FWIW, you'll get the same behaviour with
ksh93 -c "$(cat test.ksh)"
.â Kusalananda
Jul 18 at 15:37
@Kusalananda Yes. That is an even simpler example.
â Ole Tange
Jul 18 at 15:41
Strange bug. It seems to be triggered by ksh not having a script name:
ksh <test.ksh
has the same effect. It's not due to having multiple function definitions: the display is cut off after the end of the definition ofdoi1
, except for any other nested function definition.â Gilles
Jul 18 at 20:03
Can I set a (fake) script name? Somewhat similar to
$0="myname"
in perl?â Ole Tange
Jul 19 at 0:02