守则:
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语句之外,它似乎都正常工作。但我不知道它到底是怎么回事。有什么建议或帮助吗?
预告谢谢:)
发布于 2014-07-18 15:57:04
这句话说错了:
if [[ $first ]] # The first instance in each pair is the device name这将永远是正确的。[[ true ]]或[[ false ]]是[[ -n true ]]或[[ -n false ]]的同义词,它总是正确的。
你的意思可能是
if "$first"或
if [[ $first == true ]]https://stackoverflow.com/questions/24829201
复制相似问题