2011-06-16 62 views
20

我在我的bash脚本如下功能:调用程序时,bash函数同名

make() { 
    cd Python-3.2 
    make 
} 

当提出的是这个脚本中调用这个函数被调用,这递归。在函数内调用make实际上应该调用外部make工具。除了重命名我的make功能,最简单的方法是什么?

回答

41

您可以使用内置的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. 
+2

这种方法比使用'which'实用的好处是,它会避免推出额外的过程。 – 2011-06-16 00:19:57

+0

这正是正确的答案。 – 2011-06-16 00:35:09

+0

+1:我完全忘记了这一点。 – 2011-06-16 00:56:59

9

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

如果你不知道的完整路径,可以使用which工具,如:

$(which make) 

这将找到的完整路径和执行make