代码:
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语句之外,似乎一切正常。但我无法弄清楚它有什么问题。有什么建议或帮助吗?
预先谢谢你:)
答案 0 :(得分:6)
这是错误的界限:
if [[ $first ]] # The first instance in each pair is the device name
总是评估为真。 [[ true ]]
或[[ false ]]
与[[ -n true ]]
或[[ -n false ]]
同义,但始终是正确的。
你可能意味着什么
if "$first"
或者
if [[ $first == true ]]