bash - Bash 语法:如果 [ ! -F \”{}\” ]; 然后退出1;菲'
问题描述
我正在 Apache Airflow 的 Bash Operator 中阅读这个 bash 命令,尽管尝试了一些谷歌搜索,但我还是无法真正理解它。
if [ ! -f \"{}\" ]; then exit 1; fi
在这个代码块中:
check_file_existence = BashOperator(
task_id='check_file_existence',
bash_command='if [ ! -f \"{}\" ]; then exit 1; fi'.format(input_file))
你能帮我解释一下这个 bash 命令吗?
解决方案
该format()
方法将替换{}
为 的值input_file
。如果值为input_file
is somefile.txt
,则 shell 命令将变为
if [ ! -f "somefile.txt" ]; then exit 1; fi
如果文件不存在,这将以非零状态码退出,指示错误。
该if
语句并不是真正需要的,因为[
ortest
命令本身的工作方式相同。它可以简化为
check_file_existence = BashOperator(
task_id='check_file_existence',
bash_command='test -f \"{}\"'.format(input_file))
推荐阅读
- assembly - gdb:文件如何找到传入的参数?
- azure - 从单个函数方法中读取 host.json 中的设置
- php - Alamofire Swift:上传超过 10mb 的文件?
- java - 无法理解优先队列流程
- php - 如何将选中的复选框选项保存到数据库并生成将在单独页面上搜索的唯一订单号?
- reactjs - 单击条时更改条颜色 plotly-react.js
- pyspark - 根据 PySpark 中其他数据框的列值创建指标数组
- angular - NgBootstrap v1.1.2 文档在哪里?
- xml - xsl:for-每个具有属性的元素
- c++ - 为什么 -1 在 C++ 中变成 -842150451?