Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

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

$ z thethethe
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
add comment

3 Answers

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
add comment

This should do the job:

VARIABLE=thethethe
echo ${VARIABLE//the/THE}
THETHETHE
share|improve this answer
add comment

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
add comment

Your Answer

 
discard

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.