bashbash4

Is it possible in Bash 4.0 to substring and uppercase a variable in one


Given a variable var=toucan I can do the following:

echo ${var^^}
TOUCAN
echo ${var:3}
can

Is it possible to do something similar to echo ${var:3^^} to get CAN?

echo ${var:3^^}
bash: var: 3^^: syntax error: operand expected (error token is "^")

Solution

  • No; bash doesn't let you combine special parameter expansions like that (for any of them, including remove-affix, value-if-null, value-if-null-or-empty, etc.) You will have to do it in two steps, or use a program outside of bash.