Bash Scripting - VariablesWhat will this script output? var=5 var=$((var + 3)) echo $varAErrorB5 + 3Cvar + 3D8Check Answer
Step-by-Step SolutionSolution:Step 1: Understand arithmetic expansion$((var + 3)) calculates the sum of var and 3, which is 5 + 3 = 8.Step 2: Assign and print the new valuevar is updated to 8, so echo prints 8.Final Answer:8 -> Option DQuick Check:Arithmetic expansion updates variable = D [OK]Quick Trick: Use $(( )) for math in variables [OK]Common Mistakes:MISTAKESPrinting expression as stringNot using $(( )) for mathExpecting error from arithmetic
Master "Variables" in Bash Scripting9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Bash Scripting Quizzes Bash Scripting Basics - Creating a script file (.sh) - Quiz 11easy Bash Scripting Basics - Running scripts - Quiz 9hard Conditionals - if-then-else - Quiz 8hard Loops - Looping over files and directories - Quiz 9hard Loops - Infinite loops - Quiz 7medium Quoting and Expansion - Tilde expansion (~) - Quiz 6medium User Input - Silent input with read -s (passwords) - Quiz 10hard Variables - Accessing variables ($var and ${var}) - Quiz 15hard Variables - Unsetting variables (unset) - Quiz 12easy Variables - String variables - Quiz 10hard