Clark Kent
Clark Kent

Reputation: 31

What ${ (%):-%n} means?

I don't know what "${ (%):-%n}" means.

${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh

The output of echo ${(%):-%n} is my username.

output:
output

Upvotes: 2

Views: 628

Answers (1)

chepner
chepner

Reputation: 531075

The (%) is a parameter expansion flag, specifically the one that causes prompt escape sequences in the value of the parameter to be expanded. For example,

% x="%n"
% echo $x
%n
% echo ${(%)x}
pi

The :- operator with no parameter name causes the following text to be treated as the value of the expansion:

% echo ${:-%n}
%n

Put them together, and you get an expression that expands to your current username. The string %n is the result of the parameter expansion, which also undergoes prompt expansion.

% echo ${(%):-%n}
pi

Upvotes: 5

Related Questions