Reviewed by Aditya Kumar · Last reviewed 2026-03-24
**Why BashOperator:** Run shell commands from Airflow—trigger scripts, CLI tools. Pass dynamic params via Jinja: {{ ds }}, {{ execution_date }}, {{ params.x }}. **Arguments:** bash_command='python /path/script.py --date {{ ds }} --env prod'. For XCom: bash_command=f'python...
Why BashOperator: Run shell commands from Airflow—trigger scripts, CLI tools. Pass dynamic params via Jinja: {{ ds }}, {{ execution_date }}, {{ params.x }}.
Arguments: bash_command='python /path/script.py --date {{ ds }} --env prod'. For XCom: bash_command=f'python script.py --input {ti.xcom_pull(task_ids="prev")}'.
Production: Use env vars for secrets, not command line (visible in logs). Quote paths. Prefer PythonOperator for complex logic—easier testing. Virtualenv in command if needed: /path/to/venv/bin/python script.py.
BashOperator(task_id='run', bash_command='python etl.py --date {{ ds }}')
Red Flag: Hardcoding paths or secrets in bash_command. Pro-Move: 'We inject env via BashOperator env param; secrets from Airflow Variables.'
According to DataEngPrep.tech, this is one of the most frequently asked Python/Coding interview questions, reported at 1 company. DataEngPrep.tech maintains an editor-reviewed database of 1,863 data engineering interview questions across 7 categories.