Add more debug info#607
Merged
JiepengTan merged 1 commit intogoplus:devfrom Apr 23, 2025
Merged
Conversation
| @@ -0,0 +1,99 @@ | |||
| #!/bin/bash | |||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |||
| cd $SCRIPT_DIR | |||
Contributor
There was a problem hiding this comment.
warning: Use 'cd ... || exit' or 'cd ... || return' in case cd fails. [SC2164]
Details
lint 解释
这个lint结果表明在脚本中使用了cd ...命令,但没有处理可能的失败情况。如果cd命令执行失败,脚本将继续执行后续的命令,这可能会导致意外的行为。
错误用法
cd /path/to/directory
# 如果 cd 失败,脚本会继续执行
echo "Directory changed"正确用法
cd /path/to/directory || exit 1
# 或者
cd /path/to/directory || return 1
# 如果 cd 失败,脚本会退出或返回错误码
echo "Directory changed"💡 以上内容由 AI 辅助生成,如有疑问欢迎反馈交流
| if [ -n "$font_path" ]; then | ||
|
|
||
| cp "$font_path" "$target_font_path" | ||
| if [ $? -ne 0 ]; then |
Contributor
There was a problem hiding this comment.
note: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?. [SC2181]
Details
lint 解释
这个lint结果提示你在检查命令的退出状态时,应该直接使用if ! mycmd;这样的形式,而不是通过间接地检查$?变量。这样可以更清晰和准确地判断命令是否成功执行。
错误用法
mycmd
if [ $? -ne 0 ]; then
echo "Command failed"
fi在这个错误的示例中,我们首先运行了mycmd命令,然后通过检查$?变量来判断命令是否成功执行。虽然这种方法在大多数情况下是有效的,但lint工具建议直接使用if ! mycmd;的形式。
正确用法
if ! mycmd; then
echo "Command failed"
fi在这个正确的示例中,我们直接使用了if ! mycmd;的形式来检查命令的退出状态。这种方式更加简洁和直观,符合lint工具的建议。
💡 以上内容由 AI 辅助生成,如有疑问欢迎反馈交流
nighca
approved these changes
Apr 23, 2025
84d6aff to
26ea72a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.