"type" builtin - inconsistent behaviour for non-executable files

Asked by William Andrea

If you have a non-executable file in the PATH, the "type" builtin will show it, just like an executable file. However, "type -a" does not. Is this expected behaviour, or is it a bug?

For example:

$ touch non-exec
$ PATH=.
$ type non-exec
non-exec is ./non-exec
$ type -a non-exec
bash: type: non-exec: not found

The manpage describes this behaviour, but it doesn't explain why it exists. Personally, I would have expected "type" and "type -a" to behave the same.

I stumbled on this while writing a Bash function that expands on "type", providing info like whether a function is marked for export, executable file type, etc, and this behaviour makes it difficult to parse "type -at".

This occurs on 17.10 with Bash 4.4.12, though I'm running 14.04 with Bash 4.3.11.

Question information

English Edit question
Ubuntu bash Edit question
No assignee Edit question
Last query:
Last reply:
Revision history for this message
actionparsnip (andrew-woodhead666) said :

If you suspect an issue then please report a bug

Can you help with this problem?

Provide an answer of your own, or ask William Andrea for more information if necessary.

To post a message you must log in.