Bird
0
0

You want to create a temporary directory for your script to store files safely and remove it after use. Which command correctly creates this directory and stores its path in a variable named tempdir?

hard🚀 Application Q15 of 15
Bash Scripting - File Operations in Scripts
You want to create a temporary directory for your script to store files safely and remove it after use. Which command correctly creates this directory and stores its path in a variable named tempdir?
Atempdir=$(mktemp)
Btempdir=mktemp -d
Ctempdir=$(mktemp -d)
Dtempdir=mktemp -f
Step-by-Step Solution
Solution:
  1. Step 1: Understand -d option in mktemp

    The -d option tells mktemp to create a temporary directory instead of a file.
  2. Step 2: Correct command substitution syntax

    Use $(mktemp -d) to execute the command and assign the directory path to tempdir.
  3. Final Answer:

    tempdir=$(mktemp -d) -> Option C
  4. Quick Check:

    Use $(mktemp -d) for temp directory creation [OK]
Quick Trick: Use $(mktemp -d) to create and assign temp directory [OK]
Common Mistakes:
MISTAKES
  • Assigning command as string without $()
  • Using mktemp without -d creates a file, not directory
  • Using invalid options like -f

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes