It looks like you have type
aliased to type -a
. Aliases are not inherited by any shell scripts you run from your terminal, and scripts are run in non-interactive mode by default.
Because scripts are run in a non-interactive shell, ~/.bashrc
won't be sourced when bash runs the script, so aliases defined there won't be loaded.
Without -a
, type
will "indicate how it would be interpreted if used as a command name" - i.e. it will show you what would actually be run. With -a
, it will show you all possible matches - executables in $PATH
(both direct and via following symlinks), aliases, functions)
e.g. on my system, grep
is aliased:
$ type grep
grep is aliased to `grep --directories=skip --binary-files=without-match'
$ type -a grep
grep is aliased to `grep --directories=skip --binary-files=without-match'
grep is /bin/grep
$ type -P grep
/bin/grep
My aliases aren't inherited if I run type
in a (non-interactive) instance of bash:
$ bash -c 'type grep'
grep is /bin/grep
If I force bash to be run in interactive mode, it will source ~/.bashrc
(which, in turn, sources my ~/.bash-aliases
file).
$ bash -i -c 'type grep'
grep is aliased to `grep --directories=skip --binary-files=without-match'
NOTE: it's not a good idea to just make your scripts use bash -i
as their interpreter. Instead, define any aliases or functions needed in your script in the script itself, or source them from another file. Or just use the command with whatever options are needed in the script - aliases are a convenience to minimise repetitive typing, which isn't really needed in a script. BTW, type
's -P
option is generally the most useful option in a script.
See 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.