bash - 如何推迟打印错误,直到每次执行
问题描述
目前我遍历目录.py
中的每个文件/
。对于每次迭代,我pycodestyle
一看到错误就调用并退出。
但是我想查看每个文件的所有错误消息,即使任何文件在 << 之前有错误,这有助于开发人员查看他/她应该更改哪些行以通过测试(linting)。
如果没有文件打印错误,则不要打印错误。<< 这对我的 Jenkins 管道很有用。
for file in $(find /-type d -name test -prune -o -type f -name '*.py' -print); do filename=$(basename $file) if [[ $filename != "__init__.py" ]] ; then echo "$file" pycodestyle "${file}" || exit 1 <<< This causes an error. << If it passes the linting, it doesn't exit. fi done
我的解决方案:
不知何故,我需要一个布尔局部变量来显示它是否打印错误。最后我可以检查变量并返回退出与否。但我不知道如何实现这个......谢谢!
解决方案
而不是退出,设置一个变量,您在最后进行测试,以便您以正确的状态退出。
status=0
for file in $(find /-type d -name test -prune -o -type f -name '*.py' ! -name '__init__.py' -print); do
echo "$file"
pycodestyle "${file}" || status=1
done
exit "$status"
__init__.py
此外,您可以在命令中过滤掉find
,因此您不需要if
(我在Exclude a certain directory while (find command) - BASH中向您展示了相同的内容)。
另外,请参阅为什么循环查找的输出是不好的做法?
推荐阅读
- r - 使用 ifelse 中的 grepl 对 R 中的标签进行分类
- regex - 如何使用 Powershell 将文件名的前 7 个字符移动到末尾
- jvm - OrientDB 集群模式下的 Java OutOfMemory 错误
- wordpress - 使 WordPress 插件在 document.ready 之后加载
- javascript - 计时器应该为jquery中forloop中的每个元素开始和结束
- python - 是否有始终以 0.x 开头的浮点数的字符串格式?
- python - 如何在 python 上使用自定义拆分创建新列
- c++ - 以 QMap 作为输入序列的 QtConcurrent map
- r - 为什么filled.contour() 中的轮廓线与contour() 中的轮廓线不完全相同?
- laravel-5 - Laravel 5 Auth::user() 除了 index() 函数和刀片模板外,其他地方都是空的