如何名单中包括bash的功能? [英] how to list included bash functions?

查看:111
本文介绍了如何名单中包括bash的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个名为文件中定义一个bash函数 FNAME a.sh 的:

Define a bash function fname in a file named a.sh:

fname(){
  echo "Foo"
}

我们可以包括在这样的功能:

We can include the function in this way:

源a.sh

之后,我们可以在外壳调用 FNAME 。我不知道是否有可显示所有所包含的功能的一种方式。

After that we can call the fname in the shell. I wonder if there is a way to display all the included functions.

谢谢!

推荐答案

要列出所有声明的功能和身体,你可以运行:

To list all the declared functions and the body, you can run :

set

declare -f

如果你只想要函数的名称:

If you only want the functions names :

declare -f -F 

declare -f -F | cut -d " " -f3 

注意,排版是德$ p $ 2013 pcated

Note that typeset is deprecated in 2013

和来自 http://wiki.bash-hackers.org/scripting/obsolete关于排版

此密切相关的上方,并且要经常使用
  一起。排版的存在主要是为ksh的兼容性,但
  标记为巴什(虽然我不完全同意德pcated $ P $
  这个)。这有点是有道理的,因为未来的兼容性不能
  得到保证,而且在所有的任何兼容性需要理解
  其他炮弹和分歧的非POSIX功能。运用
  声明以代替排版强调你的意图是
  庆典专用,绝对打破了其他地方(除了可能
  zsh的,如果你幸运的话)。该问题是由短跑和进一步复杂化
  对于本地内建Debian政策要求,这本身是不
  与Bash和其他shell完全兼容。

This is closely related to the above, and should often be used together. typeset exists primarily for ksh compatibility, but is marked as "deprecated" in Bash (though I don't entirely agree with this). This somewhat makes sense, because future compatibility can't be guaranteed, and any compatibility at all requires understanding the non-POSIX features of other shells and their differences. Using declare instead of typeset emphasizes your intention to be "bash-only", and definitely breaks everywhere else (except possibly zsh if you're lucky). The issue is further complicated by Dash and the Debian policy requirement for a local builtin, which is itself not entirely compatible with Bash and other shells.

这篇关于如何名单中包括bash的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆