2011-06-16 24 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