1

I have shell script that uses type -t, but since apparently it was originally written for bash and on this machine I on zsh, it's not working.

I see bash docs that type -t does:

If the -t option is used, type prints a single word which is one of ‘alias’, ‘function’, ‘builtin’, ‘file’ or ‘keyword’, if name is an alias, shell function, shell builtin, disk file, or shell reserved word, respectively. If the name is not found, then nothing is printed, and type returns a failure status.

But in zsh, type doesn't accept the -t option, and it actually aliases to whence:

type [ -fpam ] name ... Same as whence -v.

And whence:

For each name, indicate how it would be interpreted if used as a command name. The '-v' flag produces a more verbose report. The '-c' flag prints the results in a csh-like format and takes precedence over '-v'. The '-f' flag causes the contents of a shell function to be displayed, which would otherwise not happen unless the '-c' flag were used. The '-p' flag does a path search for name even if it is an alias, reserved word, shell function or builtin. The '-a' flag does a search for all occurrences of name throughout the command path. With the '-m' flag, the arguments are taken as patterns (which should be quoted), and the information is displayed for each command matching one of these patterns.

Which does not included the desired output. A way to get the en equivalent result on zsh? Changing shells is not an option on this machine.

2

As outputs from whence -w in zsh and type -t in bash are something similar (the following table is made from personal tests, so I recommend take it with care)

type -t    whence -w
alias      alias
function   function
builtin    builtin
file       command
keyword    reserved
?          hashed
?          none

It seems not too difficult to create a script in zsh that mimics the behaviour of type -t in bash. You could even, e.g. by means of alias, replace the builtin type in zsh with your command in zsh

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.