0
0
Bash Scriptingscripting~10 mins

Uppercase and lowercase conversion in Bash Scripting - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Uppercase and lowercase conversion
Start with input string
Apply uppercase conversion
Store or print uppercase result
Apply lowercase conversion
Store or print lowercase result
End
The script takes a string, converts it to uppercase, then to lowercase, and outputs both results.
Execution Sample
Bash Scripting
input="Hello World"
upper=${input^^}
lower=${input,,}
echo "$upper"
echo "$lower"
This script converts 'Hello World' to uppercase and lowercase, then prints both.
Execution Table
StepVariableValueActionOutput
1input"Hello World"Assign input string
2upper"HELLO WORLD"Convert input to uppercase using ${input^^}
3lower"hello world"Convert input to lowercase using ${input,,}
4Print uppercase stringHELLO WORLD
5Print lowercase stringhello world
6End of script
💡 Script ends after printing both uppercase and lowercase strings.
Variable Tracker
VariableStartAfter Step 2After Step 3Final
input"Hello World""Hello World""Hello World""Hello World"
upper"HELLO WORLD""HELLO WORLD""HELLO WORLD"
lower"hello world""hello world"
Key Moments - 3 Insights
Why does ${input^^} convert the string to uppercase?
Because in bash, the ^^ operator converts all characters in the variable to uppercase, as shown in execution_table step 2.
What does ${input,,} do differently from ${input^^}?
The ,, operator converts all characters to lowercase, as shown in execution_table step 3, unlike ^^ which converts to uppercase.
Why do we see no change in the original 'input' variable?
Because the conversion operators create new variables 'upper' and 'lower' without modifying the original 'input', as tracked in variable_tracker.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 2, what is the value of 'upper'?
A"Hello World"
B"hello world"
C"HELLO WORLD"
D"HELLO world"
💡 Hint
Check the 'Value' column for 'upper' at step 2 in execution_table.
At which step does the script print the lowercase string?
AStep 5
BStep 3
CStep 4
DStep 2
💡 Hint
Look at the 'Action' and 'Output' columns in execution_table to find when lowercase is printed.
If we change ${input^^} to ${input^}, what would happen to 'upper'?
AAll characters become uppercase
BOnly the first character becomes uppercase
CAll characters become lowercase
DNo change to the string
💡 Hint
Recall bash parameter expansion: ^ uppercases first char, ^^ uppercases all chars.
Concept Snapshot
Bash uppercase: ${var^^} converts all letters to uppercase
Bash lowercase: ${var,,} converts all letters to lowercase
Original variable stays unchanged
Use echo to print results
Simple and fast string case conversion
Full Transcript
This bash script starts by assigning the string 'Hello World' to the variable 'input'. Then it creates a new variable 'upper' by converting all letters of 'input' to uppercase using ${input^^}. Next, it creates 'lower' by converting all letters of 'input' to lowercase using ${input,,}. The script then prints the uppercase string followed by the lowercase string. The original 'input' variable remains unchanged throughout. This shows how to easily convert string cases in bash scripting.