运行 通过脚本间接命令时的不同结果
different result when running command indirectly though script
我在虚拟环境下使用pylint
。
直接运行ning pylint时,我得到以下输出
$ pylint src/**/*.py
************* Module main
src/main.py:1:0: C0114: Missing module docstring (missing-module-docstring)
src/main.py:3:0: C0116: Missing function or method docstring (missing-function-docstring)
------------------------------------------------------------------
Your code has been rated at 5.00/10 (previous run: 5.00/10, +0.00)
当相同的命令包含在 bash 脚本中时,执行 bash 脚本会产生不同的输出
$ $SHELL --version | head -n 1
GNU bash, version 5.0.18(1)-release (x86_64-apple-darwin19.5.0)
$ which $SHELL
/usr/local/bin/bash
$ cat lint.sh
#!/usr/local/bin/bash
pylint *.py src/**/*.py
$ ./lint.sh
************* Module src/**/*.py
src/**/*.py:1:0: F0001: No module named src/**/*.py (fatal)
--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
其中 lint.sh
和 src
目录在同一(根)目录中,lint.sh
中的 src/**/*.py
是正确的。
这里有更多关于执行环境的信息
$ pylint --version
pylint 2.6.0
astroid 2.4.2
Python 3.8.5 (default, Aug 9 2020, 16:57:39)
[Clang 12.0.0 (clang-1200.0.26.2)]
- 为什么 运行 直接使用命令与 运行 间接使用相同命令产生不同的输出(在 bash 脚本中,我的假设是它与 pylint 无关直接)?
- 如何解决才能在 bash 脚本中 运行 命令?
您正在脚本中使用 **
。需要激活此功能:
shopt -s globstar
pylint *.py src/**/*.py
很可能,它已在您的交互式 shell 中启用,这就是它在那里工作的原因。您可以通过执行
来查询其设置
shopt globstar
我在虚拟环境下使用pylint
。
直接运行ning pylint时,我得到以下输出
$ pylint src/**/*.py
************* Module main
src/main.py:1:0: C0114: Missing module docstring (missing-module-docstring)
src/main.py:3:0: C0116: Missing function or method docstring (missing-function-docstring)
------------------------------------------------------------------
Your code has been rated at 5.00/10 (previous run: 5.00/10, +0.00)
当相同的命令包含在 bash 脚本中时,执行 bash 脚本会产生不同的输出
$ $SHELL --version | head -n 1
GNU bash, version 5.0.18(1)-release (x86_64-apple-darwin19.5.0)
$ which $SHELL
/usr/local/bin/bash
$ cat lint.sh
#!/usr/local/bin/bash
pylint *.py src/**/*.py
$ ./lint.sh
************* Module src/**/*.py
src/**/*.py:1:0: F0001: No module named src/**/*.py (fatal)
--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
其中 lint.sh
和 src
目录在同一(根)目录中,lint.sh
中的 src/**/*.py
是正确的。
这里有更多关于执行环境的信息
$ pylint --version
pylint 2.6.0
astroid 2.4.2
Python 3.8.5 (default, Aug 9 2020, 16:57:39)
[Clang 12.0.0 (clang-1200.0.26.2)]
- 为什么 运行 直接使用命令与 运行 间接使用相同命令产生不同的输出(在 bash 脚本中,我的假设是它与 pylint 无关直接)?
- 如何解决才能在 bash 脚本中 运行 命令?
您正在脚本中使用 **
。需要激活此功能:
shopt -s globstar
pylint *.py src/**/*.py
很可能,它已在您的交互式 shell 中启用,这就是它在那里工作的原因。您可以通过执行
来查询其设置shopt globstar