创建一个取消自身的ksh函数

时间:2016-05-31 04:08:42

标签: bash shell scripting ksh scripting-language

在ksh93这个barfs:

source foo.ksh
foo die

当foo.ksh只包含:

foo() {
  echo Foo!
  if [[ "$1" = "die" ]]; then
    unset -f foo
  fi
}
在bash中,它有效。一个函数怎么能在ksh中自行解决?

1 个答案:

答案 0 :(得分:0)

同样适用于ksh。考虑foo.ksh是:

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

考虑main.ksh是:

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

给你:

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

检查[ here ]