Bash Scripting - String OperationsWhy does this code produce no output?var="file." echo ${var#*.}ABecause the pattern '*.' does not match any prefixBBecause the variable is emptyCBecause the pattern '*.' matches the entire string and removes allDBecause the pattern '*.' is invalid syntaxCheck Answer
Step-by-Step SolutionSolution:Step 1: Analyze the pattern '*.'The pattern '*.' matches the shortest prefix ending with '.'. Here, the entire 'file.' matches.Step 2: Remove the matched prefixRemoving the entire string leaves nothing, so no output.Final Answer:Because the pattern '*.' matches the entire string and removes all -> Option CQuick Check:Pattern '*.' matches entire 'file.', output empty [OK]Quick Trick: Pattern can remove entire string if it matches full prefix [OK]Common Mistakes:MISTAKESAssuming variable is emptyThinking pattern is invalidConfusing suffix removal with prefix removal
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 7medium Arrays - Accessing array elements - Quiz 14medium Arrays - Array slicing - Quiz 15hard Error Handling - Exit codes ($?) - Quiz 14medium Error Handling - Error logging patterns - Quiz 14medium Error Handling - set -e for exit on error - Quiz 1easy Error Handling - Error logging patterns - Quiz 10hard Functions - Why functions organize reusable code - Quiz 9hard Functions - Function definition - Quiz 8hard Text Processing in Scripts - Here strings (<<<) - Quiz 10hard