How to uppercase the command line argument?
The syntax str^^
which you are trying is available from Bash 4.0 and above. Perhaps yours is an older version (or you ran the script with sh
explicitly):
Try this:
str="Some string"
printf '%s\n' "$str" | awk '{ print toupper($0) }'
echo "lowercase" | tr a-z A-Z
Output:
LOWERCASE
Be careful with tr unless A-Z is all you use. For other locales even '[:lower:]' '[:upper:]' fails, only awk's toupper and bash (v4+) works
$ str="abcåäö"
$ echo "$str"|tr '/a-z/' '/A-Z/'
ABCåäö
$ echo "$str"|LC_ALL=sv_SE tr '[:lower:]' '[:upper:]'
ABCåäö
$ echo "$str"|awk '{print toupper($0)}'
ABCÅÄÖ
$ echo ${str^^} # Bash 4.0 and later
ABCÅÄÖ
$ STR="ABCÅÄÖ"
$ echo ${STR,,}
abcåäö