Bird
0
0

Identify the error in this script snippet:

medium📝 Debug Q14 of 15
Bash Scripting - File Operations in Scripts
Identify the error in this script snippet:
tempfile=mktemp
echo $tempfile
rm $tempfile
AMissing parentheses to execute mktemp command
Brm command should be before echo
Cmktemp should be quoted
DNo error, script works fine
Step-by-Step Solution
Solution:
  1. Step 1: Check variable assignment

    Assigning tempfile=mktemp sets the string 'mktemp', not the command output.
  2. Step 2: Correct command substitution

    Use tempfile=$(mktemp) to run the command and assign its output.
  3. Final Answer:

    Missing parentheses to execute mktemp command -> Option A
  4. Quick Check:

    Use $(mktemp) to assign command output [OK]
Quick Trick: Use $(command) to assign output, not plain text [OK]
Common Mistakes:
MISTAKES
  • Assigning command name as string instead of output
  • Forgetting $() or backticks for command substitution
  • Thinking rm order affects error here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes