Prompt sequences undergo a special form of expansion. This type of expansion
is also available using the -P
option to the print
builtin.
If the PROMPT_SUBST
option is set, the prompt string is first subjected to
parameter expansion,
command substitution and
arithmetic expansion.
See
section Expansion.
Certain escape sequences may be recognised in the prompt string.
If the PROMPT_BANG
option is set, a `!
' in the prompt is replaced
by the current history event number. A literal `!
' may then be
represented as `!!
'.
If the PROMPT_PERCENT
option is set, certain escape sequences that
start with `%
' are expanded.
Some escapes take an optional integer argument, which
should appear between the `%
' and the next character of the
sequence. The following escape sequences are recognized:
%%
%
'.
%)
)
'.
%d
%/
$PWD
).
%~
$PWD
.
If it has a named directory as its prefix, that part is replaced
by a `~
' followed by the name of the directory.
If it starts with $HOME
, that part is
replaced by a `~
'.
%c
%.
%C
$PWD
.
An integer may follow the `%
' to get more than one component.
Unless `%C
' is used, tilde contraction is performed first.
%h
%!
%L
$SHLVL
.
%M
%m
.
'.
An integer may follow the `%
' to specify
how many components of the hostname are desired.
%S
(%s
)
%U
(%u
)
%B
(%b
)
%t
%@
%T
%*
%n
$USERNAME
.
%w
-
dd format.
%W
/
dd/
yy format.
%D
-
mm-
dd format.
%D{
string}
strftime
function.
See man page strftime(3) for more details. Three additional codes are
available: %f
prints the day of the month, like %e
but
without any preceding space if the day is a single digit, and
%K
/%L
correspond to %k
/%l
for the hour of the day
(24/12 hour clock) in the same way.
%l
%?
%_
if
' and
`for
') that have been started on the command line. If given an integer
number that many strings will be printed; zero or no integer means
print as many as there are.
%E
%#
#
' if the shell is running with privileges, a `%
' if not.
Equivalent to `%(!.#.%%)
'.
The definition of `privileged', for these purposes, is that either the
effective user ID is zero, or, if POSIX.1e capabilities are supported, that
at least one capability is raised in either the Effective or Inheritable
capability vectors.
%v
psvar
array parameter. Following
the `%
' with an integer gives that element of the array.
%{
...%}
%(
x.true-text.false-text)
)
' may appear in the false-text as `%)
'.
true-text
and false-text may both contain arbitrarily-nested escape
sequences, including further ternary expressions.
The left
parenthesis may be preceded or followed by a positive integer n,
which defaults to zero. The test character x may be any of the
following:
c
.
~
/
C
t
T
d
D
w
?
#
g
L
SHLVL
parameter is at least n.
S
SECONDS
parameter is at least n.
v
psvar
has at least n elements.
_
!
%<
string<
%>
string>
%[
xstring]
%
xstringx',
i.e. x may be `<
' or `>
'.
The numeric argument, which in the third form may appear immediately
after the `[
', specifies the maximum permitted length of
the various strings that can be displayed in the prompt. If this
integer is zero, or missing, truncation is disabled. Truncation is
initially disabled.
The string will be displayed in
place of the truncated portion of any string.
The forms with `<
' truncate at the left of the string,
and the forms with `>
' truncate at the right of the string.
For example, if the current directory is `/home/pike
',
the prompt `%8<..<%/
' will expand to `..e/pike
'.
In this string, the terminating character (`<
', `>
' or `]
'),
or in fact any character, may be quoted by a preceding `\
'.
% escapes are not recognised.
If the string is longer than the specified truncation length,
it will appear in full, completely replacing the truncated string.
Go to the first, previous, next, last section, table of contents.