On Mon, Aug 10, 2015 at 10:18:52AM +0200, Juanma wrote: > > [ is an ordinary command (a "shell builtin") > > Here is another point I find confusing: I thought a "shell builtin" didn't > have a separate binary executable file, like 'cd' (which cd => fail), but > some of them do have such form (which [ => /usr/bin/[ ; which pwd => > /bin/pwd). I also fail to see how 'test' modifies the state of the shell > itself (like 'cd' does), or why it is "impossible or inconvenient to obtain > [its functionality] with separate utilities".
Don't use which(1). Which is an external program, so it has no knowledge of the shell's builtins, aliases, functions and keywords. Instead, use type. imadev:~$ type cd cd is a shell builtin imadev:~$ type [[ [[ is a shell keyword imadev:~$ type -a test test is a shell builtin test is /usr/bin/test test is /bin/test Bash implements test as a builtin not because it's necessary, but simply for efficiency. Forking a whole process to test whether two strings are equal would be horribly wasteful.