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

发布于 2024-11-15 10:12:00 字数 205 浏览 1 评论 0原文

我的 bash 脚本中有以下函数:

make() {
    cd Python-3.2
    make
}

当在此脚本中调用 make 时,将调用该函数,并进行递归。在函数内部调用 make 实际上应该调用外部 make 实用程序。除了重命名我的 make 函数之外,实现此目的最简洁的方法是什么?

I have the following function in my bash script:

make() {
    cd Python-3.2
    make
}

When make is called within this script, this function is invoked, which recurses. The call to make inside the function should actually invoke the external make utility. Other than renaming my make function, what's the cleanest way to achieve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

合约呢 2024-11-22 10:12:00

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

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.

You can use the command built-in to suppress shell function lookups.

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.
蒲公英的约定 2024-11-22 10:12:00

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

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

$(which make)

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

Use the full path to the program. E.g. /usr/bin/make.

If you don't know the full path, you can use the which utility, like:

$(which make)

That will find the full path and execute make.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文