Bash Scripting - String OperationsWhat does the bash expression ${var/old/new} do?AReplaces the first occurrence of 'old' with 'new' in the variable 'var'BReplaces all occurrences of 'old' with 'new' in the variable 'var'CDeletes the variable 'var' if it contains 'old'DPrints the variable 'var' without any changesCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand the syntax ${var/old/new}This syntax replaces only the first occurrence of 'old' with 'new' in the string stored in 'var'.Step 2: Differentiate from global replacementUsing double slashes like ${var//old/new} replaces all occurrences, but single slash replaces only the first.Final Answer:Replaces the first occurrence of 'old' with 'new' in the variable 'var' -> Option AQuick Check:String replacement first occurrence = C [OK]Quick Trick: Single slash replaces first occurrence only [OK]Common Mistakes:MISTAKESConfusing single slash with double slashThinking it replaces all occurrencesAssuming it deletes textAssuming no change occurs
Master "String Operations" in Bash Scripting9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Bash Scripting Quizzes Arrays - Adding and removing elements - Quiz 9hard Arrays - Array slicing - Quiz 14medium Arrays - Associative arrays (declare -A) - Quiz 2easy Error Handling - Why error handling prevents silent failures - Quiz 11easy Error Handling - Exit codes ($?) - Quiz 7medium Error Handling - Error logging patterns - Quiz 5medium File Operations in Scripts - File descriptors and redirection - Quiz 1easy Functions - Why functions organize reusable code - Quiz 11easy Functions - Function arguments ($1, $2 inside function) - Quiz 10hard Text Processing in Scripts - sed for substitution in scripts - Quiz 11easy