Bird
0
0

Which command safely creates a temporary file and stores its path in a variable named tempfile in bash?

easy🧠 Conceptual Q2 of 15
Bash Scripting - File Operations in Scripts
Which command safely creates a temporary file and stores its path in a variable named tempfile in bash?
Atempfile=mktemp
Btempfile=$(mktemp)
Ctempfile=$(tempfile)
Dtempfile=mktemp -d
Step-by-Step Solution
Solution:
  1. Step 1: Correct command usage

    To create a temporary file and assign its path to a variable, use command substitution: tempfile=$(mktemp).
  2. Step 2: Analyze other options

    tempfile=mktemp assigns the string 'mktemp' instead of executing the command. tempfile=$(tempfile) calls a non-existent command 'tempfile'. tempfile=mktemp -d tries to create a directory but assigns it incorrectly.
  3. Final Answer:

    tempfile=$(mktemp) -> Option B
  4. Quick Check:

    Is command substitution used? Yes. [OK]
Quick Trick: Use $(mktemp) to assign temp file path [OK]
Common Mistakes:
MISTAKES
  • Assigning command name as string instead of executing
  • Using wrong command substitution syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes