哈希命令文档在哪里?

哈希命令文档在哪里?

当我打字时man hash它会显示我man builtin

我试图理解这一行:

hash -r 2>/dev/null || true

做什么hash -r以及返回什么。

语境:

export PATH="$PWD/bin:$PATH"
hash -r 2>/dev/null || true

https://github.com/rbenv/rbenv/wiki/Understanding-binstubs#adding-project-specific-binstubs-to-path

答案1

hash是一个 shell 内置的。

如果您正在使用bash,请检查:

help hash

为了您的方便,这里是:

哈希:哈希 [-lr] [-p 路径名] [-dt] [名称 ...]

Remember or display program locations.

Determine and remember the full pathname of each command NAME.  If
no arguments are given, information about remembered commands is displayed.

Options:
  -d                forget the remembered location of each NAME
  -l                display in a format that may be reused as input
  -p pathname       use PATHNAME as the full pathname of NAME
  -r                forget all remembered locations
  -t                print the remembered location of each NAME, preceding
            each location with the corresponding NAME if multiple
            NAMEs are given
Arguments:
  NAME              Each NAME is searched for in $PATH and added to the list
            of remembered commands.

Exit Status:
Returns success unless NAME is not found or an invalid option is given.

对于其他 shell,请检查内置函数的常用位置。例如,对于zsh,检查:

man zshbuiltins

hash -r 做什么以及它返回什么。

hash -r从哈希表中删除所有记住的位置并返回成功。

答案2

hash 是一个标准化的 shell 内置函数,它hash -r会重置当前路径散列,该散列用于在PATH.

然而,不需要hash -r在设置后调用,因为更改会自动重置当前命令散列。对于和 for 来说都是如此,我希望其他 shell 也能有同样的行为。PATHPATHBourne Shellksh

相关内容