The format()
method will replace {}
with the value of input_file
. If the value of input_file
is somefile.txt
, the shell command will become
if [ ! -f "somefile.txt" ]; then exit 1; fi
This will exit with a non-zero status code, indicating an error, if the file doesn't exist.
The if
statement isn't really needed, since the [
or test
command itself works the same way. It can be simplified to
check_file_existence = BashOperator(
task_id='check_file_existence',
bash_command='test -f "{}"'.format(input_file))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…