Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

A simple question, but I can't find the answer. the zsh documentation overwhelms me :-(

function z ()
  echo ${1:s/the/THE}

$ z thethethe


How can I get all 'the' to be replaced with 'THE', not just the first occurrence? With zsh it's the easiest things that seem to be the hardest to find examples for.

share|improve this question

This is a history expansion modifier, so add the g modifier immediately before s.

echo ${1:gs/the/THE}

Alternatively, use the parameter expansion syntax where a double slash means a global substitution. In this case, the part after s// is a wildcard pattern, whereas history expansion substitution takes a literal string.

echo ${1//the/THE}
share|improve this answer

This should do the job:

echo ${VARIABLE//the/THE}
share|improve this answer

Thereyago, it had to be simple:

echo ${1//the/THE}

... the double slash does it, and you can't fool around with " :s "

BTW, I'd sure like to thank the 'StackExchange' sites for existing. Of all the zillions of places one might ask a question, these are by far the best--one not only almost always gets answers, but those answers are invariably of the highest quality.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.