A. bash_command should be a string, not bare command
B. task_id cannot contain underscores
C. BashOperator requires a Python callable, not a string
D. Missing import statement for BashOperator
Solution
Step 1: Check bash_command syntax
bash_command must be a string, so it should be quoted like 'ls -l'.
Step 2: Verify other options
task_id can have underscores; BashOperator accepts strings; import is assumed outside task definition.
Final Answer:
bash_command should be a string, not bare command -> Option A
Quick Check:
bash_command needs quotes = B [OK]
Hint: Always quote bash_command string [OK]
Common Mistakes:
Not quoting bash_command string
Thinking task_id can't have underscores
Confusing BashOperator with PythonOperator
5. You want to create a BashOperator task that lists all files in /tmp and saves the output to /tmp/file_list.txt. Which is the correct bash_command to use?
hard
A. bash_command='ls /tmp > file_list.txt'
B. bash_command='ls /tmp | /tmp/file_list.txt'
C. bash_command='ls /tmp >> /tmp/file_list.txt'
D. bash_command='ls /tmp > /tmp/file_list.txt'
Solution
Step 1: Understand output redirection
The '>' operator redirects output to a file, overwriting it.
Step 2: Check file paths and command correctness
bash_command='ls /tmp > /tmp/file_list.txt' correctly redirects 'ls /tmp' output to '/tmp/file_list.txt'. bash_command='ls /tmp >> /tmp/file_list.txt' appends instead of overwriting, which may be unwanted. bash_command='ls /tmp | /tmp/file_list.txt' uses pipe incorrectly. bash_command='ls /tmp > file_list.txt' writes to relative path, not /tmp.
Final Answer:
bash_command='ls /tmp > /tmp/file_list.txt' -> Option D
Quick Check:
Use '>' to redirect output to full path file [OK]
Hint: Use '>' for overwrite redirection with full file path [OK]
Common Mistakes:
Using pipe '|' instead of redirection '>'
Forgetting to specify full file path
Using '>>' when overwrite is needed
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.