自己买了一个数码相机,柯达7590。自己拍了一些照片。欣赏时,感觉自己还有点专业水准,拿来作桌面。这么多图片到底选那一个,放弃那一个呢?最后决定,都选,都用来左桌面,让系统每30分钟自动换一个。利用系统子带的工具cron. 再加上自己编写的脚本,很容易实现。下面给出从文件夹中随机取出一副图片的脚本程:
[code]#!/bin/bash
#trim the charactor in head and tail
L_trim()[/code]
该函数取掉变量rand_time左边所有的空格:
[code]tmp=${rand_time:0:1}
while [ $tmp = 0 ]
do
rand_time=${rand_time:1}
tmp=${rand_time:0:1}
done
}
R_trim()[/code]
{该函数取掉变量rand_time右边所有的空格:
[code]{
Len=${#rand_time}
let "sLen =Len -1"
tmp=${rand_time:sLen:1}
while [ $tmp = 0 ]
do
rand_time=${rand_time:0:$sLen}
Len=${#rand_time}
let "sLen =Len -1"
tmp=${rand_time:sLen:1}
done
}
#get current time as random
rand_time=`date '+%N'`
#trim the "0" from the var
#rand_time=${rand_time:0:6}
L_trim
R_trim
#get filecount of $1
fcount=`ls $1 | wc -l`
echo "fcount $fcount"
#get a random number between 1 and fcount
rand_num=$(($rand_time % $fcount ))
echo $rand_num
tmp=1
for file in $1/*.jpg
do
if [ $tmp -lt $rand_num ]
then
let "tmp=tmp+1"
continue
fi[/code]
可以将随机取出的图片设为桌面:
[code]#qiv -Tx $HOME/.wallpaper.jpg
echo "file:$file"
break;
done[/code]


aifly 于 2011-02-09 15:58:52发表:
学习了
wangkezhu 于 2011-01-31 09:02:32发表:
非常好啊嘎嘎
windnest 于 2011-01-29 22:18:05发表:
看不懂 惭愧:0wszxc
mg271603433 于 2011-01-05 17:21:34发表:
挺不错的。
xuechaojie 于 2010-12-18 18:06:43发表:
:0w5ty(1:0w5ty(1
思润1018 于 2010-12-05 21:38:06发表:
俺还不到欣赏脚本的水平.{:3_108:}
lp518 于 2010-12-05 19:43:05发表:
不错啊
daidengke 于 2010-05-30 22:58:41发表:
学习一下
hurricane668 于 2010-05-24 20:55:29发表:
看得迷糊糊的
飞虎小白龙 于 2010-05-24 10:30:11发表:
正好坐下慢慢学习啊!!!
飞虎小白龙 于 2010-05-21 10:14:44发表:
学习学习啊!!!
axbyc123 于 2010-04-19 12:44:50发表:
谢谢分享
axbyc123 于 2010-04-19 12:44:45发表:
学习了
axbyc123 于 2010-04-19 12:44:28发表:
不错
jan729 于 2010-04-18 23:59:03发表:
study
坏boy 于 2010-04-17 12:43:35发表:
It was kind of interesting!
xtygaht 于 2010-03-04 23:06:46发表:
有点看不懂
liu351128 于 2010-03-04 22:35:55发表:
最后一个挺好玩的
逍遥の石头 于 2010-03-04 22:16:41发表:
混分下资料,不过也来观摩一下高手
pomerl 于 2010-02-28 01:11:00发表:
{:3_107:}。。。没懂
michrykitty 于 2007-12-25 15:11:10发表:
对 坐下来慢慢学习啊
spark1313 于 2006-10-19 16:06:44发表:
:0L :0L :0L :0L :0L
spark1313 于 2006-10-19 16:00:34发表:
zai lai yici
chameleon 于 2006-10-16 22:37:56发表:
以后多发些这样的啊
于 2006-10-16 20:52:30发表:
:0D1 :0D1
邱建元 于 2006-10-16 11:57:20发表:
坐下来慢慢学习