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

时间:2021-05-17 16:46:15

I have the following function in my bash script:

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

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?

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

2 个解决方案

#1


47  

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

您可以使用内置命令来禁止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.

#2


10  

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

使用程序的完整路径。例如。在/ usr / bin中/制作。

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.

这将找到完整路径并执行make。

#1


47  

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

您可以使用内置命令来禁止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.

#2


10  

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

使用程序的完整路径。例如。在/ usr / bin中/制作。

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.

这将找到完整路径并执行make。