MQ Ksh Shell脚本-陷阱错误

时间:2018-08-17 23:47:14

标签: linux shell ksh

我的ksh脚本如下。

if [ `uname` == "AIX" ]; then
    export LIBPATH_BKP_$$=$LIBPATH
    # Trap so that it will return the original library path when script exits
    trap 1 2 3 9 15 "export LIBPATH=$LIBPATH_BKP_$$; unset LIBPATH_BKP_$$"
    export LIBPATH=/usr/mqm/lib:$LIBPATH
else # All else will be either Linux or Solaris which uses LD_LIBRARY_PATH
    export LD_LIBRARY_PATH_BKP_$$=$LD_LIBRARY_PATH
    # Trap so that it will return the original library path when script exits
    trap 1 2 3 9 15 "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH_BKP_$$; unset LD_LIBRARY_PATH_BKP_$$"
    export LD_LIBRARY_PATH=/usr/mqm/lib:$LD_LIBRARY_PATH_BKP_$$
fi

当我执行它时说

tdestop.ksh [52]:陷阱:export LD_LIBRARY_PATH = 49648;未设置LD_LIBRARY_PATH_BKP_49648:错误陷阱

tdestop.ksh-是脚本名称及其在第52行的提示错误。

问题是什么是陷阱?这是怎么了?我不是这方面的专家。抱歉,这个问题真的是新手。

谢谢, 德维雅

1 个答案:

答案 0 :(得分:1)

语法是:

trap action signals...

例如

trap 'echo "I caught something"' HUP INT TERM

您已经翻转了动作和信号的顺序,这就是ksh抱怨的原因。您应该改用:

trap "export LIBPATH=$LIBPATH_BKP_$$; unset LIBPATH_BKP_$$" 1 2 3 9 15