Bash Scripting - VariablesConsider this script: ```bash export VAR1=foo VAR2=bar bash -c 'echo "$VAR1 $VAR2"' ``` What is the output?Afoo barBfoo C barDVAR1 VAR2Check Answer
Step-by-Step SolutionSolution:Step 1: Understand export effect'VAR1' is exported, so it is available in the child bash process. 'VAR2' is not exported, so it is not available.Step 2: Analyze the child bash commandThe child bash prints the values of VAR1 and VAR2. VAR1 prints 'foo', VAR2 is empty, so output is 'foo '.Final Answer:foo -> Option BQuick Check:Only exported variables appear in child processes [OK]Quick Trick: Only exported variables pass to child shells [OK]Common Mistakes:MISTAKESAssuming all variables pass to child processesConfusing export with assignmentExpecting VAR2 to print 'bar'
Master "Variables" in Bash Scripting9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Bash Scripting Quizzes Bash Scripting Basics - Why Bash scripting automates Linux tasks - Quiz 12easy Bash Scripting Basics - What a shell script is - Quiz 9hard Conditionals - Why conditionals branch script logic - Quiz 6medium Conditionals - String comparisons (=, !=, -z, -n) - Quiz 3easy Conditionals - File test operators (-f, -d, -e, -r, -w, -x) - Quiz 8hard Loops - Looping over files and directories - Quiz 6medium Loops - break and continue - Quiz 6medium Quoting and Expansion - Tilde expansion (~) - Quiz 9hard User Input - Command-line arguments ($1, $2, ...) - Quiz 4medium Variables - Unsetting variables (unset) - Quiz 12easy