megas
megas

Reputation: 21791

Mix of parameter and command substitutions

I found this snippet of code (simplified)

while read item; do
  echo -n "${(q)item} "
done

from here https://github.com/junegunn/fzf/blob/master/shell/key-bindings.zsh#L12

I don't understand the expression "${(q)item} ".

What is variable q, I didn't find any declaration of it, is it a command substitution? Why parentheses use inside curly braces? What is meaning of this construction?

Upvotes: 1

Views: 159

Answers (1)

Barmar
Barmar

Reputation: 782489

Parentheses immediately after ${ specify parameter expansion flags. The q flag is used to quote special characters in the expansion.

Quote characters that are special to the shell in the resulting words with backslashes; unprintable or invalid characters are quoted using the $'\NNN' form, with separate quotes for each octet.

Upvotes: 1

Related Questions