Shell Builtin Command 「type」

type type

執行

$ type type

顯示

type is a shell builtin

help type

執行

$ help type

顯示

type: type [-afptP] name [name ...]
    Display information about command type.

    For each NAME, indicate how it would be interpreted if used as a
    command name.

    Options:
      -a    display all locations containing an executable named NAME;
        includes aliases, builtins, and functions, if and only if
        the `-p' option is not also used
      -f    suppress shell function lookup
      -P    force a PATH search for each NAME, even if it is an alias,
        builtin, or function, and returns the name of the disk file
        that would be executed
      -p    returns either the name of the disk file that would be executed,
        or nothing if `type -t NAME' would not return `file'.
      -t    output a single word which is one of `alias', `keyword',
        `function', `builtin', `file' or `', if NAME is an alias, shell
        reserved word, shell function, shell builtin, disk file, or not
        found, respectively

    Arguments:
      NAME  Command name to be interpreted.

    Exit Status:
    Returns success if all of the NAMEs are found; fails if any are not found.

Exit Status

執行

$ type

然後再執行

$ echo $?

顯示

0

執行

$ type echo

顯示

echo is a shell builtin

然後再執行

$ echo $?

顯示

0

執行

$ type x

顯示

bash: type: x: not found

然後再執行

$ echo $?

顯示

1

執行範例

執行

$ type echo

顯示

echo is a shell builtin

執行

$ type -a echo

顯示

echo is a shell builtin
echo is /bin/echo

更多請參考「enable」和「which」的說明。

另外有一個指令是「file」,用途不太一樣。