In one of your comments, you mentioned using zsh
with a preexec
function that calls print -P $2
.
In zsh
, print -P
accepts these format characters:
%F
means set the foreground color
%S
means set the standout attribute
See zsh prompt expansion for the full list.
So it's probably best to remove the -P
flag from your call to print
in preexec
.
One way to get the same effect:
settitle() {
printf "%b%s%b" "\033]0;" "$1" "\007"
}
tildedir() {
print -Pn "%~"
}
preexec() {
settitle "$(tildedir):$2"
}
From your comments, you seem to be confused about exactly what a shell is. The kernel is responsible for managing the system. It's the part that actually loads and runs programs, accesses files, allocates memory, etc. But the kernel has no user interface; you can only communicate with it by using another program as an intermediary.
A shell is a program that prints a prompt, reads a line of input from you, and then interprets it as one or more commands to manipulate files or run other programs. Before the invention of the GUI, the shell was the primary user interface of an OS. On MS-DOS, the shell was called command.com
and few people ever tried to use a different one. On Unix, however, there have long been multiple shells that users could pick from.
They can be divided into 3 types. The Bourne-compatible shells use the syntax derived from the original Bourne shell. C shells use the syntax from the original C shell. Then there are nontraditional shells that invent their own syntax, or borrow one from some programming language, and are generally much less popular than the first two types.
A built-in command is simply a command that the shell carries out itself, instead of interpreting it as a request to load and run some other program. This has two main effects. First, it's usually faster, because loading and running a program takes time. Of course, the longer the command takes to run, the less significant the load time is compared to the overall run time (because the load time is fairly constant).
Secondly, a built-in command can affect the internal state of the shell. That's why commands like cd
must be built-in, because an external program can't change the current directory of the shell. Other commands, like echo
, might be built-in for efficiency, but there's no intrinsic reason they can't be external commands.
Which commands are built-in depends on the shell that you're using. You'll have to consult its documentation for a list (e.g., bash
's built-in commands are listed in Chapter 4 of its manual). The type
command can tell you if a command is built-in (if your shell is POSIX-compatible), because POSIX requires that type
be a built-in. If which
is not a built-in in your shell, then it probably won't know about your shell's built-ins, but will just look for external programs.
Best Answer
zsh
is one of the few shells (the other ones beingtcsh
(which
originated as acsh
script forcsh
users, which also had its limitation,tcsh
made it a builtin as an improvement)) wherewhich
does something sensible since it's a shell builtin, but somehow you or your OS (via somerc
file) broke it by replacing it with a call to the systemwhich
command which can't do anything sensible reliably since it doesn't have access to the interns of the shell so can't know how that shell interprets a command name.In zsh, all of
which
,type
,whence
andwhere
are builtin commands that are all used to find out about what commands are, but with different outputs. They're all there for historical reason, you can get all of their behaviours with different flags to thewhence
command.You can get the details of what each does by running:
Or type
info zsh
, then bring up the index withi
, and enter the builtin name (completion is available).And avoid using
/usr/bin/which
. There's no shell nowadays where thatwhich
is needed. As Timothy says, use the builtin that your shell provides for that. Most POSIX shells will have thetype
command, and you can usecommand -v
to only get the path of a command (though bothtype
andcommand -v
are optional in POSIX (but not Unix, and not any longer in LSB), they are available in most if not all the Bourne-like shells you're likely to ever come across).(BTW, it looks like
/usr/bin
appears twice in your$PATH
, you could add atypeset -U path
to your~/.zshrc
)