【问题标题】:Invoking program when a bash function has the same name当 bash 函数具有相同名称时调用程序
【发布时间】:2011-09-15 23:39:22
【问题描述】:

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

make() {
    cd Python-3.2
    make
}

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

【问题讨论】:

    标签: bash shell


    【解决方案1】:

    您可以使用内置的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】:

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

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

    $(which make)
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-06
      • 2015-09-19
      • 2021-10-09
      • 1970-01-01
      • 2019-02-02
      • 1970-01-01
      相关资源
      最近更新 更多