"which" and "type" (was: Ubuntu installation questions)



On 2009-08-16 07:34 (-0700), Nick K. wrote:

On Aug 15, 6:11 pm, Aragorn <arag...@xxxxxxxxxxxxxxxxxxx> wrote:
If you want to know where an executable is located (or which version of
the executable you would be invoking), then it is best to use /type,/
like so...

        type latex

I have never seen a command called "type" but I suspect it must be an
internal command to the bash shell. The command "which" seems to do
the same thing and also has its own man page. What is the difference
between using one or the other?

Yes, "type" is a Bash builtin but the commands are not the same. "which"
locates a command in $PATH. It searches only for executable files in the
filesystem. Bash's "type" returns the type of command:

$ type printf
printf is a shell builtin

$ which printf
/usr/bin/printf

If I execute

$ printf "foo\n"

it will use the shell builtin. So, if you need to know "what will be
executed when I run command X without explicit path" then you need to
check "type X". "type" can also tell if command is a shell function:

$ type quote
quote is a function
quote ()
{
echo \'${1//\'/\'\\\'\'}\'
}

For more info: "help type" in Bash.
.



Relevant Pages

  • Re: Opening Dual WIndows in Batch FIle
    ... Despite the availability of spelling-checkers and syntax-analysers, the documentation contains such blunders as "hexidecimal" and displays a confusion about the use of singlar and plural. ... I've tried to analyse the syntax for the START command, and I'll admit that I've only tried unquoted and quoted strings - no unbalanced-quotes, embedded quotes or alternative separators like semicolons or tabs. ... 3b If the second argument IS quoted then an attempt will be made to execute that part of the command-line AFTER the opening quote of the second argument UP TO the final quote on the line, with parameterof the remainder of the line after the separator following the opening quote of the second argument MINUS the final quote on the line. ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: Opening Dual WIndows in Batch FIle
    ... command doesn't start with a double quote. ... I'd suggest it's very optimistic to rely on the documentation, ... I've tried to analyse the syntax for the START command, ... execute that part of the command-line AFTER the opening quote of the ...
    (microsoft.public.win2000.cmdprompt.admin)
  • [Full-Disclosure] Advanced usage of system() function.
    ... and call its arguments as a command for shell. ... as we can see we still didnt get what we want (typing exit ... Connection closed by foreign host. ... think what we want to execute. ...
    (Full-Disclosure)
  • Advanced usage of system() function.
    ... and call its arguments as a command for shell. ... as we can see we still didnt get what we want (typing exit we are ... Connection closed by foreign host. ... think what we want to execute. ...
    (Bugtraq)
  • Re: Opening Dual WIndows in Batch FIle
    ... command doesn't start with a double quote. ... I'd suggest it's very optimistic to rely on the documentation, ... 3b If the second argument IS quoted then an attempt will be made to execute ...
    (microsoft.public.win2000.cmdprompt.admin)