7

when I run this I get this 'bad substitution' error. What can I do?

$ x="Hello World"
$ echo "$x"
Hello World
$ echo "${x^^}"
-bash: ${x^^}: bad substitution

EDIT: I would like to have it in all upper case.

Tom
  • 705
  • 2
  • 9
  • 13
  • 3
    What version of `bash` are you running? – Barmar May 06 '13 at 21:59
  • 1
    Works for GNU bash, version 4.1.10(4). – Dave Jarvis May 06 '13 at 22:00
  • 2
    The case modification operators were added in bash 4. – Barmar May 06 '13 at 22:00
  • I am running this (how can I update?): GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin12) Copyright (C) 2007 Free Software Foundation, Inc. – Tom May 06 '13 at 22:01
  • 5
    The Bash that comes with OS X is ancient. [`brew install bash`](http://mxcl.github.io/homebrew/). – johnsyweb May 06 '13 at 22:02
  • @Kevin: `zsh: bad substitution` ;) – johnsyweb May 06 '13 at 23:06
  • Possible duplicate of [converting string to lower case in bash shell scripting](http://stackoverflow.com/questions/2264428/converting-string-to-lower-case-in-bash-shell-scripting). – earl May 07 '13 at 01:41
  • 1
    I don't get this: `bash --version` : `GNU bash, version 4.4.19(1)-release (x86_64-apple-darwin17.4.0)`. `ICAO="EDDF"; echo "${ICAO,,}"` yields `-bash: ${ICAO,,}: bad substitution`. Anyone knows why? – Mojo66 Jun 09 '18 at 20:51
  • @Mojo66 you're sure the bash script uses the same bash executable? Try `which bash` and compare to the shebang in the script. – tutuDajuju Jun 26 '20 at 08:21

1 Answers1

9

Your method only works in bash 4. Try this:

echo $x | tr '[a-z]' '[A-Z]'
araex
  • 133
  • 5