Bash

雜湊命令文件在哪裡?

  • March 6, 2016

當我鍵入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

hash是一個內置的外殼。

如果您正在使用bash,請檢查:

help hash

為了您的方便,這裡是:

雜湊:雜湊

$$ -lr $$ $$ -p pathname $$ $$ -dt $$ $$ name … $$

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從雜湊表中刪除所有記住的位置並返回成功。

引用自:https://unix.stackexchange.com/questions/267899