Use the syntax: ${string^^}. For example, name="hello"; echo ${name^^} outputs HELLO.
Click to reveal answer
beginner
How do you convert a string to lowercase in Bash?
Use the syntax: ${string,,}. For example, name="HELLO"; echo ${name,,} outputs hello.
Click to reveal answer
intermediate
What does ${string^} do in Bash?
It converts only the first character of the string to uppercase. For example, name="hello"; echo ${name^} outputs Hello.
Click to reveal answer
intermediate
What does ${string,} do in Bash?
It converts only the first character of the string to lowercase. For example, name="HELLO"; echo ${name,} outputs hELLO.
Click to reveal answer
beginner
Why is uppercase and lowercase conversion useful in scripting?
It helps standardize text input, making scripts more reliable when comparing or processing strings regardless of how users type them.
Click to reveal answer
Which syntax converts the entire string to uppercase in Bash?
A${string,}
B${string,,}
C${string^}
D${string^^}
✗ Incorrect
The syntax ${string^^} converts all characters in the string to uppercase.
What will echo ${name,,} output if name="HELLO"?
AHELLO
Bhello
CHello
DhELLO
✗ Incorrect
The syntax ${string,,} converts the entire string to lowercase.
How do you convert only the first letter of a string to uppercase in Bash?
A${string^}
B${string,,}
C${string^^}
D${string,}
✗ Incorrect
The syntax ${string^} converts only the first character to uppercase.
What does ${string,} do in Bash?
AConverts first character to lowercase
BConverts entire string to lowercase
CConverts first character to uppercase
DConverts entire string to uppercase
✗ Incorrect
The syntax ${string,} converts only the first character to lowercase.
Why should you convert input text to a consistent case in scripts?
ATo make scripts run faster
BTo change the meaning of commands
CTo avoid errors when comparing strings
DTo save memory
✗ Incorrect
Converting text to a consistent case helps avoid errors when comparing or processing strings.
Explain how to convert a string to uppercase and lowercase in Bash using parameter expansion.
Think about the double caret and double comma syntax.
You got /4 concepts.
Why is it important to standardize text case in automation scripts?
Consider how users might type input differently.
You got /3 concepts.
Practice
(1/5)
1. In bash scripting, which syntax converts the value of a variable name to all uppercase letters?
easy
A. Using uppercase(name)
B. Using ${name,,}
C. Using ${name^^}
D. Using toUpperCase(name)
Solution
Step 1: Understand bash variable expansion for case conversion
Bash supports ${variable^^} to convert all letters in variable to uppercase.
Step 2: Compare options with bash syntax
Using ${name^^} uses ${name^^}, which is the correct bash syntax. Using ${name,,} converts to lowercase, and options C and D are not valid bash syntax.
Final Answer:
Using ${name^^} -> Option C
Quick Check:
Uppercase conversion = ${variable^^} [OK]
Hint: Use ${variable^^} to uppercase text in bash [OK]
Common Mistakes:
Confusing uppercase and lowercase syntax
Using non-bash functions like toUpperCase()
Forgetting the double caret ^^
2. Which of the following is the correct syntax to convert the variable text to lowercase in bash?
easy
A. echo ${text,,}
B. echo ${text^^}
C. echo ${text^}
D. echo ${text,}
Solution
Step 1: Recall lowercase conversion syntax in bash
To convert all letters to lowercase, bash uses ${variable,,}.
Step 2: Analyze each option
echo ${text,,} uses ${text,,} which converts all letters to lowercase. echo ${text^^} converts to uppercase, C and D convert only the first letter.
Final Answer:
echo ${text,,} -> Option A
Quick Check:
Lowercase conversion = ${variable,,} [OK]
Hint: Use ${variable,,} to lowercase all letters in bash [OK]
Common Mistakes:
Using single comma instead of double for all letters
Mixing uppercase and lowercase syntax
Confusing ^ and , operators
3. What is the output of the following bash script?
word="HelloWorld"
echo ${word,,}
medium
A. helloworld
B. helloWorld
C. HelloWorld
D. HELLOWORLD
Solution
Step 1: Understand the variable and conversion
The variable word contains "HelloWorld". The expression ${word,,} converts all letters to lowercase.
Step 2: Apply lowercase conversion
Converting "HelloWorld" to lowercase results in "helloworld".
Final Answer:
helloworld -> Option A
Quick Check:
Lowercase conversion of HelloWorld = helloworld [OK]
Hint: Lowercase all letters with ${variable,,} [OK]
Common Mistakes:
Expecting only first letter to change
Confusing uppercase and lowercase syntax
Ignoring case conversion operator
4. The following bash script is intended to convert input to uppercase, but it does not work as expected:
input="bashScript"
echo $input^^
What is the error?
medium
A. Variable name is incorrect
B. Missing braces around the variable for case conversion
C. Using single caret instead of double caret
D. Uppercase conversion is not supported in bash
Solution
Step 1: Identify correct syntax for uppercase conversion
Bash requires braces around the variable when using case conversion, like ${input^^}.
Step 2: Analyze the script
The script uses $input^^ without braces, which is invalid syntax and will not convert case.
Final Answer:
Missing braces around the variable for case conversion -> Option B
Quick Check:
Use ${variable^^} with braces for uppercase [OK]
Hint: Always use braces ${} for case conversion in bash [OK]
Common Mistakes:
Omitting braces around variable
Using single caret ^ for all letters
Assuming bash lacks uppercase conversion
5. You have a list of filenames stored in a bash array: files=("Report1.txt" "summary2.TXT" "DATA3.Txt"). You want to convert all filenames to lowercase and print them line by line. Which script correctly does this?
hard
A. for f in "${files[@]}"; do echo tolower($f); done
B. for f in "${files[@]}"; do echo ${f^^}; done
C. for f in files; do echo ${f,,}; done
D. for f in "${files[@]}"; do echo ${f,,}; done
Solution
Step 1: Understand the goal and array iteration
The goal is to convert each filename to lowercase and print it. Iterating over "${files[@]}" correctly accesses each element.
Step 2: Check each option's correctness
for f in "${files[@]}"; do echo ${f,,}; done uses ${f,,} to convert to lowercase and iterates correctly. for f in "${files[@]}"; do echo ${f^^}; done converts to uppercase, C iterates incorrectly (missing quotes and array expansion), D uses a non-bash function tolower().
Final Answer:
for f in "${files[@]}"; do echo ${f,,}; done -> Option D
Quick Check:
Lowercase array elements with ${var,,} in loop [OK]
Hint: Use for loop with ${var,,} to lowercase array items [OK]
Common Mistakes:
Using uppercase conversion instead of lowercase
Incorrect array iteration syntax
Using non-existent bash functions
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.