Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linux 使用 os-check 巡检时报错check_linux.sh: line 41: -: -: syntax error: operand expected (error token is "-") #11

Open
ansushl opened this issue Apr 16, 2022 · 5 comments

Comments

@ansushl
Copy link

ansushl commented Apr 16, 2022

当我运行os-check 巡检后,生成的html文件报错
如图所示
image

具体报错:
check_linux.sh: line 41: -: -: syntax error: operand expected (error token is "-")
check_linux.sh: line 43: -: -: syntax error: operand expected (error token is "-")

操作系统
CentOS Linux release 7.9.2009 (Core)

@ansushl
Copy link
Author

ansushl commented Apr 17, 2022

我查看了一下,发现是在检测inode时,被传入了一个非数值参数 “-”,导致-ge对比时由于不为数值报错的,可能需要在进行ge对比时校验下是否为数字

image

@lework
Copy link
Owner

lework commented Apr 18, 2022

感谢提醒,我加了个数字判断。你可以试试。

[[ !"$value" =~ ^|0-9|+$ ]] && return

@ansushl
Copy link
Author

ansushl commented Apr 19, 2022

加了判断没有生效,我加了个判断,你可以参考下

#  value=${2:-0}
  if [[ $2 =~ '\^[1-9]+\$' ]]; then
    value=${2}
  else
    value=0
  fi

@fxkjnj
Copy link

fxkjnj commented May 11, 2022

value=${2:-0}

if [[ $2 =~ '^[1-9]+$' ]]; then
value=${2}
else
value=0
fi

试了下 这个 可以解决那个问题

@lework
Copy link
Owner

lework commented May 12, 2022

后面又重新看了下,这个还要考虑下有小数的情况,我这里又改了一版,你们试试。

# 忽略小数位,不能数字对比时,直接返回。
[[ ${value%.*} -ge 0 ]] 2>/dev/null || return

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants