0
0
Bash Scriptingscripting~10 mins

Why string manipulation is frequent in Bash Scripting - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print the length of the string stored in variable 'text'.

Bash Scripting
echo ${#[1]
Drag options to blanks, or click blank then click option'
Atext
Blength
Cstr
Dlen
Attempts:
3 left
💡 Hint
Common Mistakes
Using function names like 'len' or 'length' instead of variable name.
Forgetting to use ${#} syntax.
2fill in blank
medium

Complete the code to extract the first 4 characters from the string in variable 'word'.

Bash Scripting
echo ${word:[1]:4}
Drag options to blanks, or click blank then click option'
A1
B0
C4
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Starting at 1 which skips the first character.
Using negative indexes which are not supported in this syntax.
3fill in blank
hard

Fix the error in the code to replace all occurrences of 'a' with 'o' in variable 'text'.

Bash Scripting
echo ${text//[1]/o}
Drag options to blanks, or click blank then click option'
Ab
Bd
Cc
Da
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong letter in the pattern.
Using single slash / which replaces only first occurrence.
4fill in blank
hard

Fill both blanks to create a substring from variable 'data' starting at index 2 with length 5.

Bash Scripting
echo ${data:[1]:[2]
Drag options to blanks, or click blank then click option'
A2
B3
C5
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping start and length values.
Using wrong indexes causing unexpected substring.
5fill in blank
hard

Fill all three blanks to create a new string with 'Hello' replaced by 'Hi' in variable 'greeting', then print its length.

Bash Scripting
new=${greeting/[1]/[2]
echo ${#[3]
Drag options to blanks, or click blank then click option'
AHello
BHi
Cnew
Dgreeting
Attempts:
3 left
💡 Hint
Common Mistakes
Printing length of original variable instead of new.
Using wrong replacement strings.