bash'declare'不能在脚本中使用?

时间:2013-08-23 08:56:50

标签: bash emacs

我的`.bashrc'文件中定义了一些bash函数。在emacs中 shell-mode,我想用完整的函数名。

emacs“shell”包默认无法完成这些功能,所以我 计划加强它。

问题是我无法获得shell的当前函数定义。该 查询函数定义的常用方法是键入:

   $ declare -F

由于'declare'只是一个内置命令,我们应该把它包装成一个 脚本文件然后用`bash'调用它。有了emacs,我们可以:

   * create a file, wrap the code:

     -------------- file: get-functions -----------

     declare -F

     -------------- file end ----------------------

   * in emacs, eval the expression:

     (call-process "bash" "get-functions" "output-buffer")

但是,我在`output-buffer'中什么都没得到。有趣的是,如果我 在真实的shell中运行脚本:

  $ bash get-functions

我仍然没有得到任何结果。

这是否意味着我们不能在脚本中使用`declare -F'?

顺便说一句,如果我们从脚本文件中删除“-F”选项,那么我们就可以 调用“bash get-functions”时得到输出,但我们得到的不是函数 定义,但都是变量。

我的环境:GNU bash,版本4.1.2(1)-release(i386-redhat-linux-gnu),CentOS 6.3 32位

2 个答案:

答案 0 :(得分:0)

还没有解决方案,只是检查“declare -F”是否有效:

(shell)
(comint-send-string (get-buffer-process "*shell*") "declare -F")
(comint-send-string (get-buffer-process "*shell*") "\n")
(switch-to-buffer "*shell*") 

答案 1 :(得分:0)

从我的脑海中,我猜这与未导出的函数有关(而bash目前无法导出函数)。 换句话说:你必须找到你的功能。

...你可以通过使用登录shell来解决这个问题,但是对于我而言,使用它似乎更容易。

相关问题