If I can do this in my bash shell:
$ STRING="A String"
$ echo ${STRING^^}
A STRING
How can I change my command line argument to upper case?
I tried:
GUARD=${1^^}
This line produces Bad substitution error for that line.
If I can do this in my bash shell:
$ STRING="A String"
$ echo ${STRING^^}
A STRING
How can I change my command line argument to upper case?
I tried:
GUARD=${1^^}
This line produces Bad substitution error for that line.
Let's start with this test script:
$ cat script.sh
GUARD=${1^^}
echo $GUARD
This works:
$ bash script.sh abc
ABC
This does not work:
$ sh script.sh abc
script.sh: 1: script.sh: Bad substitution
This is because, on my system, like most debian-like systems, the default shell, /bin/sh, is not bash. To get bash features, one needs to explicitly invoke bash.
The default shell on debian-like systems is dash. It was chosen not because of features but because of speed. It does not support ^^. To see what it supports, read man dash.
With tr command:
Script:
#!/bin/bash
echo $@ | tr '[a-z]' '[A-Z]'
Check:
$ bash myscript.sh abc 123 abc
ABC 123 ABC