首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Bash if块没有运行,而它显然应该运行

Bash if块没有运行,而它显然应该运行
EN

Stack Overflow用户
提问于 2014-07-18 15:53:23
回答 1查看 142关注 0票数 0

守则:

代码语言:javascript
复制
first=true
mountpoint=" "
partlist=`df -h | grep "^/dev"` # get partition info
for i in $partlist              # loop through info
do
  if [[ ${i:0:1} = "/" ]]       # items starting with / are what I'm interested in
  then
    if [[ $first ]]             # The first instance in each pair is the device name
    then
      mountdev=$i
      mountpoint=" "
      first=false
    else                        # The second instance is the device mount point
      mountpoint=$i
      first=true
    fi
    if [[ $mountpoint != " " ]] # If the mountpoint was just set (last to be set
                                #   before printing config)
    then
      # Print config
      echo "${mountpoint} \${fs_size ${mountpoint}"
      echo "USED \${fs_used ${mountpoint}}\${alignr}\${fs_free ${mountpoint}} FREE"
      echo "\${fs_bar 3,300 ${mountpoint}}"
      echo "READ \${diskio_read  ${mountdev}}\${alignr}\${diskio_write  ${mountdev}} WRITE"
      echo ""
    fi
  fi
done

问题是:

目标是创建一个脚本,该脚本将为我的每台计算机生成我喜欢的conky配置,而不必编辑每台计算机的文件。上面是一个片段,它生成报告我的磁盘使用信息的部分。不幸的是,我很难让它输出任何东西。我向它抛出各种调试回声,除了实际输出配置的if语句之外,它似乎都正常工作。但我不知道它到底是怎么回事。有什么建议或帮助吗?

预告谢谢:)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-07-18 15:57:04

这句话说错了:

代码语言:javascript
复制
if [[ $first ]]             # The first instance in each pair is the device name

这将永远是正确的。[[ true ]][[ false ]][[ -n true ]][[ -n false ]]的同义词,它总是正确的。

你的意思可能是

代码语言:javascript
复制
if "$first"

代码语言:javascript
复制
if [[ $first == true ]]
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24829201

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档