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.

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

Tried

#!/bin/bash
             ## 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
3  
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

1 Answer 1

up vote 12 down vote accepted

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

Try this:

str="Some string"
echo $str | awk '{print toupper($0)}'

Guru.

share|improve this answer
1  
From mtk's words I understood that case modification actually works for him with variables. –  manatwork Oct 16 '12 at 12:46
1  
@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
2  
@mtk That should be tr '[a-z]' '[A-Z]'. –  l0b0 Oct 17 '12 at 9:43

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.