For example, if passed ls as input it should tell me that /bin/ls will run if run ls on the command-line.
Answer
The command to use varies from shell to shell.
Only a shell built-in will tell one correctly what the shell will do for a given command name, since only built-ins can fully know about aliases, shell functions, other built-ins, and so forth. Remember: Not all commands correspond to executable files in the first place.
For the Bourne Again shell,
bash, the built-in is thetypecommand:$ type '['
[ is a shell builtinFor the Fish shell,
fish, Thetypebuiltin works similarly to bash. To get just the path to an executable, usecommand -v:$ type cat
cat is /bin/cat
$ command -v cat
/bin/catFor the Korn Shell,
ksh, the built-in is thewhencecommand — withtypeinitially set up as an ordinary alias forwhence -vand thecommandbuilt-in with the-voption equivalent towhence:$ whence -v ls
ls is a tracked alias for /bin/lsFor the Z Shell,
zsh, the built-in is thewhencecommand, with thecommandbuilt-in with the-voption equivalent towhenceand the built-instype,which, andwhereequivalent towhencewith the options-v,-c, and-carespectively.$ whence ls
/bin/lsFor the T C Shell,
tcsh, the built-in is thewhichcommand — not to be confused with any external command by that name:> which ls
ls: aliased to ls-F
> which \ls
/bin/ls
No comments:
Post a Comment