作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在 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
的值为somefile.txt
,则shell命令会变成
if [ ! -f "somefile.txt" ]; then exit 1; fi
如果文件不存在,这将以非零状态代码退出,指示错误。
if
语句并不是真正需要的,因为 [
或 test
命令本身的工作方式相同。可以简化为
check_file_existence = BashOperator(
task_id='check_file_existence',
bash_command='test -f \"{}\"'.format(input_file))
关于Bash 语法 : if [ ! -f\"{}\"];然后退出 1;菲',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65518366/
为什么当我输入 bash 时:if [ false ];然后 echo “确定”; fi; 结果是 ok 字符串?使用变量时我也可以获得类似的结果:ok=false;如果 [$确定];然后 echo
请帮忙。执行此操作时出现错误。我该如何修复 if [ awk 'BEGIN{print 0.4*10}' > 1 -eq 1 ]; then echo YES; fi 最佳答案 shell 语法一开始
我是一名优秀的程序员,十分优秀!