关于conky:Bash如果块明显不应该运行

Bash if block doesn't run when it clearly should

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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语句之外,它似乎都正常工作。但是我不知道它出了什么问题。有什么建议或帮助吗?

提前谢谢:)


这是错误的行:

1
if [[ $first ]]             # The first instance in each pair is the device name

这样的评价总是正确的。[[ true ]][[ false ]][[ -n true ]][[ -n false ]]的同义词,通常是正确的。

你的意思可能是

1
if"$first"

1
if [[ $first == true ]]