1

In ksh93 this barfs:

source foo.ksh
foo die

when foo.ksh contains just:

foo() {
  echo Foo!
  if [[ "$1" = "die" ]]; then
    unset -f foo
  fi
}

in bash, it works. How can a function unset itself in ksh?

  • `ksh93 this barfs` -barfs how? – Мона_Сах May 31 '16 at 06:40
  • Memory fault(coredump) – user1093043 May 31 '16 at 07:08
  • Did you compile your own ksh? Your function works for me with ksh 93u+ and an ancient 88i – glenn jackman May 31 '16 at 15:24
  • Mysterious! Prompted by your comment (and the one below by @mona_sax) I searched more, and finally tracked down a system where this works. The system is running CentOS. In all others I've tried (which are: a Ubuntu laptop, a Debian server, a couple of Ubuntu servers, an OS X laptop) it barfs. The version of ksh in all cases that I've tried is 93u+; in the case of the laptops and one of the servers (the Debian one) ksh was installed from packages, for the other server I don't know. – user1093043 May 31 '16 at 17:48
  • Also works on Red Hat Enterprise Server Santiago with ksh93t+. Maybe the problem is a Debian thing? – user1093043 May 31 '16 at 18:01
  • @user1093043 : Tracing a system where it works is a big waste of time. Why didn't you debug the script instead using tools like the one suggested in this [page](http://docstore.mik.ua/orelly/unix/ksh/ch09_01.htm). If you compiled ksh use gdb to see where the `Memory Fault` happens. – Мона_Сах May 31 '16 at 18:44
  • @mona_sax: The variety of systems both under my control and not that exhibit the problem shows that this is not the result of something special I've done with ksh. In particular, as I mentioned, on several of these systems ksh is not compiled from source. – user1093043 Jul 28 '16 at 16:19

1 Answers1

0

The same works in ksh too. Consider foo.ksh is :

foo()
{
    echo "Bar"
    if [ "$1" = "die" ]
    then
    unset -f foo
    fi
}

Consider main.ksh is :

source foo.ksh
foo die
foo # you haven't checked if the function is unset or not

Gives you :

bar --> first call
main.ksh[10]: foo: not found [No such file or directory]  --> second call

Check it [ here ].

sjsam
  • 21,411
  • 5
  • 55
  • 102
  • I don't know about the website you cite, but I have checked your code (which matches mine in all important ways) in local and remote shells (multiple Universities, my VPS, within my local net) and it always gives a memory fault. – user1093043 May 31 '16 at 07:05