首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当bash函数具有相同的名称时调用程序

当bash函数具有相同的名称时调用程序
EN

Stack Overflow用户
提问于 2011-06-16 00:01:37
回答 2查看 6K关注 0票数 33

在bash脚本中有以下函数:

代码语言:javascript
复制
make() {
    cd Python-3.2
    make
}

在此脚本中调用make时,将调用此函数,该函数将递归。函数中对make的调用实际上应该调用外部make实用程序。除了重命名make函数之外,实现这个目标的最干净的方法是什么?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-06-16 00:19:06

您可以使用内置的command来抑制shell函数查找。

代码语言:javascript
复制
command: command [-pVv] command [arg ...]
    Execute a simple command or display information about commands.

    Runs COMMAND with ARGS suppressing  shell function lookup, or display
    information about the specified COMMANDs.  Can be used to invoke commands
    on disk when a function with the same name exists.

    Options:
      -p    use a default value for PATH that is guaranteed to find all of
        the standard utilities
      -v    print a description of COMMAND similar to the `type' builtin
      -V    print a more verbose description of each COMMAND

    Exit Status:
    Returns exit status of COMMAND, or failure if COMMAND is not found.
票数 63
EN

Stack Overflow用户

发布于 2011-06-16 00:02:59

使用程序的完整路径。例如/usr/bin/make

如果您不知道完整的路径,可以使用which实用程序,例如:

代码语言:javascript
复制
$(which make)

将找到完整的路径并执行make

票数 13
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6365795

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档