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

Mat*_*ner 24 bash shell

我的bash脚本中有以下功能:

make() {
    cd Python-3.2
    make
}
Run Code Online (Sandbox Code Playgroud)

在此脚本中调用make时,将调用此函数,该函数将进行递归.到呼叫make的函数内部实际上应该调用外部make实用程序.除了重命名我的make函数之外,最简单的方法是什么?

Ada*_*zak 53

您可以使用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.
Run Code Online (Sandbox Code Playgroud)

  • 使用`which`实用程序的这种方法的好处是它将避免启动额外的进程. (3认同)

Gus*_*dez 11

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

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

$(which make)
Run Code Online (Sandbox Code Playgroud)

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