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

I searched SO and found that to uppercase a string following would work

str="Some string"
echo ${str^^}

But I tried to do a similar thing on a command-line argument, which gave me the following error


             ## Output
echo ${1^^}  ## line 3: ${1^^}: bad substitution
echo {$1^^}  ## No error, but output was still smaller case i.e. no effect

Please let me know, how could we do this?

share|improve this question
It works for me just fine. Post your entire script, the error is probably elsewhere. Is your shebang pointing to bash? – manatwork Oct 16 '12 at 12:37
up vote 36 down vote accepted

The syntax str^^ which you are trying is available from Bash 4.0 and above. Perhaps yours is an older version:

Try this:

str="Some string"
echo $str | awk '{print toupper($0)}'
share|improve this answer
From mtk's words I understood that case modification actually works for him with variables. – manatwork Oct 16 '12 at 12:46
@manatwork That is not clearly stated in the initial question. The bad substitution error message is the same as you would get with older bash versions. – Bernhard Oct 16 '12 at 12:48
You are correct. I checked the version, its 3.2.25. Your solution works and also I tried tr '[a-z]' [[A-Z]'. – mtk Oct 16 '12 at 12:51
@mtk That should be tr '[a-z]' '[A-Z]'. – l0b0 Oct 17 '12 at 9:43
I'm running GNU bash, version 4.3.42(1)-release (x86_64-apple-darwin14.5.0), and I get the same error as OP, so I don't think this is available on any bash 4.0 and above as you say. – Heath Borders Jan 26 at 23:19

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.