在/ etc / profile中定义的函数体在login时出现在shell历史logging中

我们在这里运行IBM AIX(当前为7100-03-03-1415),在其他版本的UNIX中缺less相当数量的实用程序预设。 我们需要做的事情之一就是将时间从标准时间转换为标准时间。 为了解决这个问题,我创build了这个函数,并把它放在/etc/profile

 ## Functions that are useful enough to be inherited by everyone ## # Prints timestamp from epoch time epoch() { if [ $# -eq 1 ] ; then SECONDS="$1" elif [ -t 0 ] || [ $# -gt 1 ] ; then echo "Usage: epoch <timestamp>" return 127 else read SECONDS fi perl -e 'print scalar localtime $ARGV[0],"\n"' $SECONDS return 0 } 

该函数采用参数或从stdin读取并打印转换的时间戳。

由于将这个函数推送到了我们所有的LPAR中以供.sh_history使用,我注意到函数的文本在产生一个新的shell之后出现在每个用户的.sh_history

 ls -la ssh localhost if [ $# -eq 1 ] ; then SECONDS="$1" elif [ -t 0 ] || [ $# -gt 1 ] ; then echo "Usage: epoch <timestamp>" return 127 else read SECONDS fi perl -e 'print scalar localtime $ARGV[0],"\n"' $SECONDS return 0 } cat .sh_history 

我从来没有见过这样的事情。 这不会影响生产或正常运行时间,所以这比其他任何事情都更令人好奇。 很明显,加载用户的shell时正在读取函数,但是这会导致它打印到shell历史logging?

编辑添加:目前正在运行ksh版本M-11/16 / 88f。

这实际上是有意的行为; ksh自动logging历史文件中的所有函数定义。

这个选项可以用“nolog”选项closures: set -o nolog