🎓 A1Learner
🔍
0 of 46 lessons completed

Bash Parameter Case Changes

Parameter case changes switch letters between upper and lower case. A doubled operator changes every letter, and a single operator changes one letter.

All letters up or all letters down

The doubled operators change the whole value. Every letter moves to one case, and the space stays put.

name="hello World"
echo "${name^^}"
echo "${name,,}"

Only the first letter changes

The single operators touch the first letter only. The rest of each value keeps its original case.

a="hello world"
b="Hello World"
echo "${a^}"
echo "${b,}"

Single versus doubled, side by side

The same mixed-case value goes through three forms. The doubled form changes all letters, and the single form changes one.

word="hELLO wORLD"
echo "${word^^}"
echo "${word^}"
echo "${word,,}"

Example

input="jOhN dOE"
lower="${input,,}"
echo "Original: $input"
echo "Lower: $lower"
echo "Upper: ${input^^}"
echo "Capitalized: ${lower^}"

Key points

  • ${var^^}: change every letter to upper case.
  • ${var,,}: change every letter to lower case.
  • ${var^}: change only the first letter to upper case.
  • ${var,}: change only the first letter to lower case.
  • Letters already in the target case stay unchanged.
  • Digits and punctuation pass through untouched.

In this example, the input mixes upper and lower case. The ,, form lowers every letter into a clean base. The ^^ form raises every letter. The ^ form then capitalizes only the first letter of the lowered base.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

What does ${word,,} do?