代码:
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
Run Code Online (Sandbox Code Playgroud)
问题:
目标是创建一个脚本,为我的每台计算机生成我首选的conky配置,而无需为每台计算机编辑文件.以上是一个片段,生成报告我的磁盘使用信息的部分.不幸的是,我输入ANYTHING时遇到了麻烦.我把各种调试回声扔进去,除了实际输出配置的if语句之外,它似乎都正常工作.我不知道它有什么问题.有什么建议或帮助吗?
谢谢你:)
这是错误的路线:
if [[ $first ]] # The first instance in each pair is the device name
Run Code Online (Sandbox Code Playgroud)
这总是评估为真.[[ true ]]或是[[ false ]]同义词[[ -n true ]]或[[ -n false ]]总是正确的.
你可能意味着什么
if "$first"
Run Code Online (Sandbox Code Playgroud)
要么
if [[ $first == true ]]
Run Code Online (Sandbox Code Playgroud)