作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在 linux 中编写一些 bash 脚本,我只想比较两个数字。一个是磁盘大小,另一个是限制。我使用 linux cmd 获取磁盘大小并将其存储在变量中,如下所示,
declare -i output
output= df -h | grep /beep/data| awk '{ printf ("%d",$5)}'
echo "$output" # Got 80 here
limit = 80
if [ $output -eq $limit ];
then
fi
运行时出现以下错误:
line 27: [: -eq: unary operator expected"
最佳答案
output= df -h | grep /beep/data| awk '{ printf ("%d",$5)}'
应该是
output="$(df -h | grep /beep/data| awk '{ printf ("%d",$5)}')"
#Used command substitution in the previous step
还有
limit = 80
应该是
limit=80 # no spaces around =, check all your variables for this
旁注:检查[ command substitution ]并使用 [ shellcheck ]检查脚本问题
关于linux - 在 bash 脚本中使用 IF 条件比较整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38388944/
我是一名优秀的程序员,十分优秀!